following is my code to send mail:
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.Message.Recipie
This is these two lines which was casting me the problem :
m_properties.put("mail.smtp.socketFactory.port", "465");
m_properties.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
and added this line :
m_properties.put("mail.smtp.starttls.enable", "true");
After removing and adding the above lines of code it worked fine.
Try to add port 9000 to your inbound rules in your windows firewall.
This exception usually occurs when there is no service listening on the port you are trying to connect to.
Try to connect using putty
or telnet
. I can bet you will get the same error.
Verify these things:
What causes your problem is right there in the stack trace:
java.net.ConnectException: Connection refused: connect
do you need a password to connect to the SMTP server? Are you sure you are using the right settings (as in port number)? Are you behind a proxy or a firewall? Can you use those settings in a regular mail program (e.g. Thunderbird) and send mails?