无法通过javax

时间:2015-05-07 00:23:40

标签: javax.mail

我目前正在启动并运行邮件服务器。我可以通过

登录

mywebsite.com/roundcube /

从这个网站我可以适当地发送和接收电子邮件。日志显示所有邮件进出,没关系。我已经从这里发送到我的Gmail帐户并返回。

但是,我真正想做的是使用javax mail从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远程登录到该框

思想?

1 个答案:

答案 0 :(得分:1)

请参阅JavaMail常见问题解答Why do I get an error such as java.net.SocketException: Permission denied: connect when connecting to my mail server using JDK7

  

设置系统属性" java.net.preferIPv4Stack" to" true"。