我已经尝试从 Grails 应用程序发送邮件好几天了,但没有成功。我在用着:
- 圣杯 1.3.7
- 邮件1.0插件
- spring-security-core 1.2.6 插件
- 雄猫7.0.23
具体来说,我尝试从 Tomcat 服务器上部署的应用程序通过端口 25 发送邮件,无需身份验证,无需 SSL。
我尝试从部署该应用程序的 VMWare 虚拟机上使用 telnet 发送消息,但失败了。
这是我发送邮件的课程:
public boolean sendMessage(String to, String msgSubject, String msgText)
{
String host = "mail.mydomain.com";
String username = "[email protected]"; // your authsmtp username
String password = "mypassword" // your authsmtp password
String from = "[email protected]";
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)
我已经阅读了几十篇考虑此类问题的帖子,但我仍然没有设法解决问题。任何帮助表示赞赏。
*EDIT:*在没有身份验证的情况下,使用 javaMail 与 Exchange 服务器 SMTP 发送邮件是否可能会出现一些问题?