简体   繁体   English

通过Java发送邮件

[英]sending mail through Java

I am facing problem on a centOS server while sending java mails. 发送Java邮件时,我在centOS服务器上遇到问题。 Getting the following exception. 获取以下异常。

javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25, response: -1 javax.mail.MessagingException:无法连接到SMTP主机:localhost,端口:25,响应:-1


I used the following command from the command prompt and I got the mail as expected. 我从命令提示符处使用了以下命令,并且按预期方式收到了邮件。

echo "testing" | mail -s"test subject" shantanu.oa@gmail.com

The relevant entry from maillog looks like this... maillog中的相关条目如下所示:

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? 我该如何解决这个问题?

From the exception it seems like its not able to connect to the host. 从例外看来,它似乎无法连接到主机。

Have you tried the telnet stuff? 您尝试过telnet的东西吗?

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. 要检查的另一件事是IP地址解析名称是否正确。如果不正确,您可以直接使用IP代替主机来查看发生的情况。

does your smtp-server needs authentication? 您的smtp服务器需要身份验证吗? Seems so, because the cmd call with mail works. 似乎如此,因为带邮件的cmd调用有效。 In default postfix configuration a local user is allowed to send mails without authentication. 在默认的postfix配置中,允许本地用户发送未经身份验证的邮件。 And your Java application might not be a registered system user on this maschine. 并且您的Java应用程序可能不是此机器上的注册系统用户。

Try to provide username and password in your code to login to the smtp server. 尝试在代码中提供用户名和密码以登录到smtp服务器。

From the log entry 从日志条目

Mar 28 20:13:16 postfix/smtpd[10120]: fatal: no SASL authentication mechanisms

I suspect that the problem is on Postfix, of which I'm not an expert. 我怀疑问题出在Postfix上,我不是专家。 Googling for "fatal: no SASL authentication mechanisms" gives lots of interesting links: maybe have a look here or here . 谷歌搜索“致命的:没有SASL身份验证机制”提供了许多有趣的链接:也许在这里这里看看。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM