I am trying to connect to a Microsoft Exchange (2010) mail account using JavaMail 1.5.1. When I try to connect, I get the following exception.
Exception in thread "main" com.sun.mail.util.MailConnectException:
Couldn't connect to host, port: domain server, 25; timeout -1;
nested exception is:
java.net.SocketException: Permission denied: connect
Here is the code I am using.
public class SendMail
{
public void mail () throws MessagingException
{
Properties props = System.getProperties();
String protocol = "smtp";
// Setup mail server
props.put("mail." + protocol + ".host", "domain server");
props.put("mail." + protocol + ".auth", "true");
props.put("mail." + protocol + ".port", "25");
Session session = Session.getInstance(props);
Transport t = session.getTransport(protocol);
try{
t.connect("domain\\user name", "password");
}
finally{
t.close();
}
}
}
What I am doing wrong?
Replace domain server with the actual server name in exception and code.