2

Thanks in advance to any help with this. Java Mail always worked for me but now it's throwing this annoying Exception:

//Exception:

run:
DEBUG: setDebug: JavaMail version 1.4.6
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "xxxxxx", port 25, isSSL false
Exception in thread "main" java.lang.RuntimeException: javax.mail.MessagingException: Could not connect to SMTP host: xxxxxx, port: 25;
  nested exception is:
    java.net.ConnectException: Operation timed out
    at vesso.mail.TestMail.sendMail(TestMail.java:79)
    at vesso.mail.TestMail.main(TestMail.java:26)
Caused by: javax.mail.MessagingException: Could not connect to SMTP host: mail.mentorlicitacao.com.br, port: 25;
  nested exception is:
    java.net.ConnectException: Operation timed out
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1962)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:654)
    at javax.mail.Service.connect(Service.java:295)
    at vesso.mail.TestMail.sendMail(TestMail.java:71)
    ... 1 more
Caused by: java.net.ConnectException: Operation timed out
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
    at java.net.Socket.connect(Socket.java:579)
    at java.net.Socket.connect(Socket.java:528)
    at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:321)
    at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:237)
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1928)
    ... 4 more
Java Result: 1
BUILD SUCCESSFUL (total time: 1 minute 19 seconds)

I've tried to connect with Mail.app (using MacOS), and it worked fine.

//Code:

    final String host = "xxxx";
    final int port = 25;
    final String username = "xxxx";
    final String password = "xxxx";

    Properties props = new Properties();

    props.put("mail.smtp.auth", "true");

    Session session = Session.getInstance(props,
        new javax.mail.Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password);
            }
        });
    session.setDebug(true);

    try {

        Message message = new MimeMessage(session);
        message.setFrom(new InternetAddress(username));
        message.setRecipients(Message.RecipientType.TO,
                InternetAddress.parse(username));
        message.setSubject("Teste");
        message.setText("Bla, Bla, Bla!");

        Transport transport = session.getTransport("smtp");
        transport.connect (host, port, username, password);
        transport.sendMessage(message, message.getAllRecipients());
        transport.close();  


        System.out.println("Done");

    } catch (MessagingException e) {
        throw new RuntimeException(e);
    }

Thanks!

4
  • This is a network topology problem, not a coding problem. Commented Mar 6, 2013 at 22:36
  • Thanks, how can I solve it? what can I do? Commented Mar 6, 2013 at 23:51
  • Good news @EJP ! I've tried the code on a Linux machine and everything worked fine! Any idea? I'm running the last java release (1.7.0_17) on my MacOs machine. Maybe a JVM security configuration. Commented Mar 7, 2013 at 0:45
  • I answered your original post on the OTN JavaMail forum. Commented Mar 7, 2013 at 20:54

1 Answer 1

2

Problem solved by changing the port from 25 to 587. The conclusion I have reached is that my ISP blocks this port.

Thanks everyone.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.