通过Java发送邮件
我在发送 java 邮件时在 centOS 服务器上遇到问题。出现以下异常。
javax.mail.MessagingException:无法连接到 SMTP 主机:localhost,端口:25,响应:-1
我在命令提示符下使用了以下命令,并按预期收到了邮件。
echo "testing" | mail -s"test subject" [email protected]
邮件日志中的相关条目如下所示...
Mar 28 20:13:16 postfix/smtpd[10120]: fatal: no SASL authentication mechanisms
Mar 28 20:13:17 postfix/master[28163]: warning: process /usr/libexec/postfix/smtpd pid 10120 exit status 1
Mar 28 20:13:17 postfix/master[28163]: warning: /usr/libexec/postfix/smtpd: bad command startup -- throttling
Mar 28 20:26:22 postfix/smtpd[11001]: warning: SASL: Connect to private/auth failed: Connection refused
我该如何纠正该问题?
I am facing problem on a centOS server while sending java mails. Getting the following exception.
javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25, response: -1
I used the following command from the command prompt and I got the mail as expected.
echo "testing" | mail -s"test subject" [email protected]
The relevant entry from maillog looks like this...
Mar 28 20:13:16 postfix/smtpd[10120]: fatal: no SASL authentication mechanisms
Mar 28 20:13:17 postfix/master[28163]: warning: process /usr/libexec/postfix/smtpd pid 10120 exit status 1
Mar 28 20:13:17 postfix/master[28163]: warning: /usr/libexec/postfix/smtpd: bad command startup -- throttling
Mar 28 20:26:22 postfix/smtpd[11001]: warning: SASL: Connect to private/auth failed: Connection refused
How do I correct the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从日志条目中
我怀疑问题出在 Postfix 上,而我不是这方面的专家。谷歌搜索“致命:没有 SASL 身份验证机制”给出了很多有趣的链接:也许可以看看这里 或此处。
From the log entry
I suspect that the problem is on Postfix, of which I'm not an expert. Googling for "fatal: no SASL authentication mechanisms" gives lots of interesting links: maybe have a look here or here.
从异常情况来看,它似乎无法连接到主机。
你尝试过telnet吗?
还要检查的另一件事是名称到 IP 的解析是否正确进行。如果没有,您可以直接使用 IP 代替主机来查看会发生什么。
From the exception it seems like its not able to connect to the host.
Have you tried the telnet stuff?
One more thing to check would be whether the name to IP resolution is taking place properly.If not you can use the IP directly in place of host to see what happens.
您的 smtp 服务器需要身份验证吗?
看起来是这样,因为使用邮件进行 cmd 调用是有效的。在默认的 postfix 配置中,允许本地用户无需身份验证即可发送邮件。并且您的 Java 应用程序可能不是该机器上的注册系统用户。
尝试在代码中提供用户名和密码来登录 smtp 服务器。
does your smtp-server needs authentication?
Seems so, because the cmd call with mail works. In default postfix configuration a local user is allowed to send mails without authentication. And your Java application might not be a registered system user on this maschine.
Try to provide username and password in your code to login to the smtp server.