首页 新闻 赞助 找找看

java Mail 运行javamail 入门级代码出错

0
悬赏园豆:5 [已解决问题] 解决于 2016-11-18 11:18

源代码:public class SendEmail {

public static void main(String[] args) {   // 收件人电子邮箱 String to = "a@xx.com.cn";

// 发件人电子邮箱 String from = "b@xx.com.cn";

// 指定发送邮件的主机为 localhost   String host = "hikml.xxxx.com.cn";

// 获取系统属性 Properties properties = System.getProperties();

// 设置邮件服务器 properties.put("mail.smtp.host", host);   properties.put("mail.smtp.port", "25");   properties.setProperty("mail.transport.protocol", "smtp");   properties.put("mail.smtp.auth", "true");   properties.put("mail.smtp.user", "a@xx.com.cn");   properties.put("mail.smtp.password", "*******");

// 获取默认session对象 Session session = Session.getDefaultInstance(properties);   session.setDebug(true);   try {    // 创建默认的 MimeMessage 对象 MimeMessage message = new MimeMessage(session);    // Set From: 头部头字段 message.setFrom(new InternetAddress(from));

// Set To: 头部头字段 message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));

// Set Subject: 头部头字段 message.setSubject("This is the Subject Line!");

// 设置消息体 message.setText("This is actual message");

// 发送消息 Transport.send(message);    System.out.println("Sent message successfully....");   } catch (MessagingException mex) {    mex.printStackTrace();   } }

}

就是网上的一个初级教程,但是一直调不通。hikml.xxxx.com.cn这是公司内部邮件服务器。能平通,使用25端口能telnet连通。 错误: javax.mail.AuthenticationFailedException: failed to connect, no password specified?     at javax.mail.Service.connect(Service.java:329)     at javax.mail.Service.connect(Service.java:176)     at javax.mail.Service.connect(Service.java:125)     at javax.mail.Transport.send0(Transport.java:194)     at javax.mail.Transport.send(Transport.java:124)     at com.support.mail.SendEmail.main(SendEmail.java:70)

彪 哥的主页 彪 哥 | 初学一级 | 园豆:189
提问于:2016-10-13 20:44
< >
分享
最佳答案
0

需要授权。

收获园豆:5
羊皮纸月亮 | 初学一级 |园豆:154 | 2016-10-14 17:53
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册