我正在尝试使用JavaMail 1.5.1连接到Microsoft Exchange(2010)邮件帐户。当我尝试连接时,我得到以下异常。
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
这是我正在使用的代码。
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();
}
}
}
我做错了什么?
将 域服务器 替换为例外和代码中的实际服务器名称。