1

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.

uranibaba
  • 712
  • 1
  • 13
  • 30
  • have you tried with smtps and have you verified the port ? – Keval Mar 20 '15 at 14:48
  • Try these [connection debugging tips](http://www.oracle.com/technetwork/java/javamail/faq/index.html#condebug). Is your code running in an app server where the security manager might be preventing you from connecting? – Bill Shannon Mar 20 '15 at 18:26
  • I believe the problem is one or all of the following: 1. Wrong port 2. Incorrect credential format (not "dom\juser\J.User" as they suggest in the FAQ). 3. Protocol is wrong. I'll have to talk to the who set up the Exchange server for more details (he is on vacation). – uranibaba Mar 24 '15 at 05:41

1 Answers1

-2

SMTP is not started by default on exchange servers so i'd recommend simply using exchange itself

specializt
  • 1,913
  • 15
  • 26