Skip to content
Advertisement

MailConnectException while sending mail using java mail api

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 this statement

JavaScript

Can anyone tell me what I’m doing wrong?

JavaScript

Stack trace:

JavaScript

Advertisement

Answer

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

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement