ist_lion
ist_lion

Reputation: 3209

Can use webmail but cannot send via javax.mail

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

Upvotes: 0

Views: 1171

Answers (1)

Federico Sierra
Federico Sierra

Reputation: 5206

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

Upvotes: 5

Related Questions