0

I currently have a mail server up and running. I can log into my web-mail client via mywebsite.com/roundcube/

Web-mail allows me to send and receive email appropriately. Logs show all the mail come in and out and it's fine. I've sent from here to my gmail account and back.

However, what I really want to do is send some mail from java using javax mail. So I can automate e-mails

I've tried configuring as follows:

    final String username = "myusername";
    final String password = "mypassword";

Properties props = new Properties();
        props.put("mail.smtp.host", "localhost");
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.port", "25");
        props.put("mail.debug","true");

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

When I go to send the message via

Transport.send(message);

I get the following output:

DEBUG: JavaMail version 1.5.0-b01
DEBUG: setDebug: JavaMail version 1.5.0-b01
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "localhost", port 25, isSSL false
Exception in thread "main" java.lang.RuntimeException: javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25;
  nested exception is:
    java.net.SocketException: Permission denied: connect

I can telnet to the box via localhost on port 25

Thoughts?

Edit: Netstat Info

myname@mybox:~/Development$ netstat -plnt | grep 25
tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN      -

Edit 2: I'm using Postfix + Courier and based my set-up from http://flurdy.com/docs/postfix/#data

2
  • Output of netstat -tulpn?
    – masegaloeh
    May 7, 2015 at 1:22
  • Netstat info added per request
    – ist_lion
    May 7, 2015 at 1:34

1 Answer 1

5

By default Java preferred IPv6, try set the -Djava.net.preferIPv4Stack=true JVM property to force application to use an IPv4 socket to communicate.

1
  • Setting that was the fix. Thank you so much!
    – ist_lion
    May 7, 2015 at 3:39

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.