我目前正在启动并运行邮件服务器。 我可以通过mywebsite.com/roundcube /
登录我的网络邮件客户端网络邮件允许我适当地发送和接收电子邮件。日志显示所有邮件进出,没关系。我已经从这里发送到我的Gmail帐户并返回。
但是,我真正想做的是使用javax邮件从java发送一些邮件。所以我可以自动发送电子邮件
我尝试过配置如下:
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);
当我通过
发送消息时Transport.send(message);
我得到以下输出:
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
我可以通过端口25上的localhost远程登录到该框
思想?
编辑:Netstat信息
myname@mybox:~/Development$ netstat -plnt | grep 25
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN -
编辑2: 我使用Postfix + Courier并根据我的设置 http://flurdy.com/docs/postfix/#data
答案 0 :(得分:4)
默认情况下,Java首选IPv6,请尝试设置-Djava.net.preferIPv4Stack=true
JVM属性以强制应用程序使用IPv4套接字进行通信。