Reputation: 3209
I currently have a mail server up and running. I can log into it via
mywebsite.com/roundcube/
From this site I can 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.
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?
Upvotes: 0
Views: 606
Reputation: 11065
See the JavaMail FAQ, Why do I get an error such as java.net.SocketException: Permission denied: connect when connecting to my mail server using JDK7.
Set the System property "java.net.preferIPv4Stack" to "true".
Upvotes: 1