带有 MS Exchange 的 JavaMail:服务器和客户端都不支持身份验证机制
2022-09-04 05:22:11
我已经尝试从Grails应用程序发送邮件好几天了,但没有成功。我正在使用:
- 圣杯 1.3.7
- 邮件 1.0 插件
- 弹簧-安全-核心 1.2.6 插件
- 雄猫 7.0.23
具体来说,我正在尝试从部署在Tomcat服务器上的应用程序使用Exchange发送邮件,该端口25没有身份验证,没有SSL。
我尝试从部署应用程序的VMWare虚拟机使用telnet发送消息,但它已经失败了。
这是我的发送邮件的类:
public boolean sendMessage(String to, String msgSubject, String msgText)
{
String host = "mail.mydomain.com";
String username = "myuser@mydomain.com"; // your authsmtp username
String password = "mypassword" // your authsmtp password
String from = "myuser@mydomain.com";
Properties props = System.getProperties();
props.put("mail.smtp.host", host);
props.put("mail.smtp.user", username);
props.put("mail.smtp.password", password);
props.put("mail.smtp.port", "25"); // thish is the port recommended by authsmtp
props.put("mail.smtp.auth", "false");
Session session = Session.getDefaultInstance(props, null);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
InternetAddress to_address = new InternetAddress(to);
message.addRecipient(Message.RecipientType.TO, to_address);
message.setSubject(msgSubject);
message.setText(msgText);
Transport transport = session.getTransport("smtp");
transport.connect(host, username, password);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
return true;
}
这是错误堆栈跟踪:
javax.mail.AuthenticationFailedException: No authentication mechansims supported by both server and client
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:590)
at javax.mail.Service.connect(Service.java:291)
at javax.mail.Service.connect(Service.java:172)
at javax.mail.Service$connect.call(Unknown Source)
at org.helpdesk.MymailService.sendMessage(MymailService.groovy:37)
at org.helpdesk.MymailService$sendMessage.call(Unknown Source)
at org.helpdesk.RequestController$_closure13.doCall(RequestController.groovy:247)
at org.helpdesk.RequestController$_closure13.doCall(RequestController.groovy)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
我已经阅读了几十篇考虑此类问题的帖子,但我仍然没有设法解决问题。任何帮助是值得赞赏的。
*编辑:*在没有身份验证的情况下,使用javaMail和Exchange服务器SMTP发送邮件是否有可能出现一些问题?