JavaMail的与微软的Exchange:由服务器和客户端支持无身份验证mechansims

问题描述:

我一直试图天,现在从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

  • 春季安全内核1.2.6插件

  • 的Tomcat 7.0.23

Specifficaly我试图与Exchange与应用程序部署Tomcat服务器trought端口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.

这是我的发送邮件类:

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)

我读过考虑这样的问题,几十个职位,但我仍然还没有设法解决这个问题。任何帮助是AP preciated。

I've read few dozen posts considering problems like this but I've still havent manage to solve the problem. Any help is appreciated.

*的编辑:的*是否有可能存在一些问题发送使用JavaMail邮件与Exchange服务器SMTP时,有没有验证

**Is it possible that there are some problems sending mails using javaMail with Exchange server SMTP when there is no authentication?

如果你试图连接到您的邮件服务器的没有的验证,调用的 connect方法没有的采取用户名和密码。如果你传递一个用户名和密码,它认为你的真正的要进行身份验证,并因为它无法找到服务器支持的认证机制,它失败。

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.