MailConnectException while sending mail using java mail api

家住魔仙堡 提交于 2019-11-28 14:32:35
Caadi0

This looks like network problem. Even though it could occur due to variety of reasons, like :-

"Couldn't connect to host, port" could be caused by wrong host name, wrong port, a blocking firewall (on the server, on gateways, even on your own machine), network failure, server downtime, etc.

Can you connect to the mail server using telnet ?

Also see this FAQ for some mistakes you committed http://www.oracle.com/technetwork/java/javamail/faq/index.html#commonmistakes

Read this answer on how to send emails using gmail https://stackoverflow.com/a/47452/3107043

Session session = Session.getInstance(props, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
    return new PasswordAuthentication(username, password);
}
});   
props.put("mail.smtp.port", "587");  transport.send(message);

After 8 hours of pain, I've solved this by turning off:

1) my windows firewall

2) my antivirus software

hope this helps

I met the same problem, and the reason is that I opened a vpn. Hope this will be helpful.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!