带有 MS Exchange 的 JavaMail:服务器和客户端均不支持身份验证机制 [英] JavaMail with MS Exchange: No authentication mechansims supported by both server and client
问题描述
我几天来一直在尝试从 Grails 应用程序发送邮件,但没有成功.我正在使用:
I've been trying for days now to send mail from Grails application and unsuccessfully. I'm using:
- grails 1.3.7
- 邮件 1.0 插件
- spring-security-core 1.2.6 插件
- tomcat 7.0.23
特别是我试图从部署在 Tomcat 服务器上的应用程序通过 Exchange 发送邮件,通过端口 25 发送邮件,无需身份验证,无需 SSL.
Specifficaly I'm trying to send mail with Exchange from application deployed on Tomcat server trought port 25 with no authentication, no SSL.
我已尝试从部署了该应用程序的 VMWare 虚拟机使用 telnet 发送消息,但它已通过.
I've tried to send message with telnet from the VMWare virtual machine on which the app is deployed and it got trough.
这是我发送邮件的课程:
This is my class for sending mails:
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)
我已经阅读了几十篇考虑此类问题的帖子,但我仍然没有设法解决问题.任何帮助表示赞赏.
I've read few dozen posts considering problems like this but I've still havent manage to solve the problem. Any help is appreciated.
**在没有身份验证的情况下,使用带有 Exchange 服务器 SMTP 的 javaMail 发送邮件是否可能存在一些问题?
**Is it possible that there are some problems sending mails using javaMail with Exchange server SMTP when there is no authentication?
推荐答案
如果您尝试没有身份验证连接到邮件服务器,请调用不会 获取用户名和密码.如果您将用户名和密码传递给它,它会认为您真的想要进行身份验证,并且由于它找不到服务器支持的身份验证机制,因此它会失败.
If you're trying to connect to your mail server without authentication, call the connect method that doesn't take a username and password. If you pass it a username and password, it thinks you really want to authenticate, and since it can't find an authentication mechanism that the server supports, it fails.
这篇关于带有 MS Exchange 的 JavaMail:服务器和客户端均不支持身份验证机制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!