Trying to send an email using java mail api. And I keep getting MailConnectException. I have tried multiple ways to solve it without success.
Exception is thrown by
For me, de-activating firewall and anti-virus did not work. I tried the alternate ports given in the mailtrap's SMTP settings 25 or 465 or 587 or 2525
changing spring.mail.port
to 2525 in the applications.properties file worked for me
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.
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