dra*_*ago 9 java authentication grails exchange-server jakarta-mail
我几天来一直试图从Grails应用程序发送邮件但没有成功.我正在使用:
Specifficaly我正在尝试使用部署在Tomcat服务器上的应用程序发送邮件,该端口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;
}
Run Code Online (Sandbox Code Playgroud)
这是错误堆栈跟踪:
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)
Run Code Online (Sandbox Code Playgroud)
我已经阅读了几十个帖子,考虑到这样的问题,但我仍然无法解决问题.任何帮助表示赞赏.
*编辑:*如果没有身份验证,是否可能在使用带有Exchange服务器SMTP的javaMail发送邮件时出现问题?
Bil*_*non 19
如果您尝试在未经身份验证的情况下连接到邮件服务器,请调用不带用户名和密码的connect方法.如果您传递用户名和密码,它认为您确实要进行身份验证,并且由于无法找到服务器支持的身份验证机制,因此无法进行身份验证.
And*_*ner 18
在我的情况下,我不得不设置属性
"mail.smtp.ehlo"
Run Code Online (Sandbox Code Playgroud)
至 "false"
(除了加入到设置属性"mail.smtp.auth"
来"false"
然而其似乎是默认根据此链接)
在设置"mail.smtp.ehlo"
于"false"
我看到下面的调试输出(通过设置属性启用"mail.debug"
到"true"
):
DEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM
DEBUG SMTP: mechanism LOGIN not supported by server
DEBUG SMTP: mechanism PLAIN not supported by server
DEBUG SMTP: mechanism DIGEST-MD5 not supported by server
DEBUG SMTP: mechanism NTLM not supported by server
Run Code Online (Sandbox Code Playgroud)
然后得到相同的javax.mail.AuthenticationFailedException
.
(在这种情况下,SMTP服务器是Microsoft的)
归档时间: |
|
查看次数: |
38166 次 |
最近记录: |