【发布时间】:2012-03-14 17:14:45
【问题描述】:
您好,我已经编写了一个代码,用于使用 java mail 从我的服务器发送邮件
这是我的代码
Properties pros = new Properties();
pros.put("mail.smtp.host", "my Ip Adress");
pros.put("mail.smtp.auth", "true");
pros.put("mail.smtp.port", "25");
Session mailSession = Session.getDefaultInstance(pros,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("emailId","password");
}
});
Message message = new MimeMessage(mailSession);
message.setFrom(new InternetAddress("sendingAddress"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("recieverAddress"));
message.setSubject("Testing Subject");
message.setText("Dear Mail Crawler," +
"\n\n No spam to my email, please!");
Transport.send(message);
return "SUCCESS";
我在代码中提供的所有细节都是正确的,我的意思是属性设置,我已经检查过了。但不幸的是,它显示了一些错误消息,例如身份验证失败
错误信息是这样的
javax.mail.AuthenticationFailedException
有人对此有任何想法吗?
我正在为我的项目使用 struts2 框架。
【问题讨论】:
标签: java struts2 jakarta-mail