Java Mail 简单实例 出现的问题

来源:互联网 发布:utc行家怎么样知乎 编辑:程序博客网 时间:2024/05/18 03:33

原码如下:

import java.util.*;
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
 
public class SendMail {
    public static void main(String[] args) {
        try {
            Properties p = new Properties(); //Properties p = System.getProperties();
            p.put("mail.smtp.auth", "true");
            p.put("mail.transport.protocol", "smtp");
            p.put("mail.smtp.host", "smtp.163.com");
            p.put("mail.smtp.port", "25");

System.out.println("建立会话.....");
            Session session = Session.getInstance(p);
System.out.println("建立信息.....");
            Message msg = new MimeMessage(session);
 
            msg.setFrom(new InternetAddress("ahhqdyh@163.com")); //发件人
            msg.setRecipient(Message.RecipientType.TO,
                             new InternetAddress("ahhqdyh@163.com")); //收件人
     msg.setSentDate(new Date()); // 发送日期
            msg.setSubject("答话稀有"); // 主题
            msg.setText("快点下在"); //内容
System.out.println("邮件服务器进行验证......");

 try{
            Transport tran = session.getTransport("smtp");
            tran.connect("smtp.163.com", "bluebit_cn", "xiaohao");           
            tran.sendMessage(msg, msg.getAllRecipients()); // 发送
System.out.println("邮件服务器进行验证成功");
System.out.println("邮件发送成功");
 }catch(Exception e){
System.out.println("邮件服务器进行验证失败");
 }

          
 
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

编译通过了,但执行时出现:

javax.mail.NoSuchProviderException: smtp
                                  at javax.mail.Session.getService(Session.java:780)
                                  at javax.mail.Session.getTransport(Session.java:718)
                                  at javax.mail.Session.getTransport(Session.java:661)
                                  at javax.mail.Session.getTransport(Session.java:641)
                                  at SendMail.main(SendMail.java:28)

根据意思表示为SMTP对象是空的,,是不是和163的邮件服务器有关呀,我的系统不用加载什么SMTP服务吧?

请高手指点一下,谢谢!!!!!!!

原创粉丝点击