如何为Microsoft Exchange配置JavaMail?

时间:2015-03-20 14:43:43

标签: java javamail exchange-server-2010

我正在尝试使用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();
        }
    }
}

我做错了什么?

域服务器 替换为例外和代码中的实际服务器名称。

1 个答案:

答案 0 :(得分:-2)

在交换服务器上

SMTP is not started by default,所以我只推荐using exchange itself