浪也回头 2016-10-13 12:39 采纳率: 0%
浏览 1072

java mail 运行demo 提示错误

源代码: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)

  • 写回答

3条回答 默认 最新

  • threenewbee 2016-10-13 13:22
    关注

    问你的邮件服务器的管理员用的何种加密方式,用户名密码是否正确。

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog