无法通过 javax 发送邮件

Unable to send mail via javax

我目前有一个邮件服务器 运行。我可以通过

登录

我的网站。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 上的本地主机远程登录到盒子

想法?

Si te Jawamile Fak,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".