简体   繁体   中英

sending mail through Java

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" shantanu.oa@gmail.com

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?

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.

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.

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. Googling for "fatal: no SASL authentication mechanisms" gives lots of interesting links: maybe have a look here or here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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