无法通过javax发送邮件

时间:2022-02-05 00:10:50

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.

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

However, what I really want to do is send some mail from java using javax mail.

但是,我真正想做的是使用javax mail从java发送一些邮件。

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

我可以通过端口25上的localhost远程登录到该框

Thoughts?

1 个解决方案

#1


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.

请参阅JavaMail FAQ,为什么我会收到诸如java.net.SocketException之类的错误:权限被拒绝:使用JDK7连接到我的邮件服务器时连接。

Set the System property "java.net.preferIPv4Stack" to "true".

将System属性“java.net.preferIPv4Stack”设置为“true”。

#1


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.

请参阅JavaMail FAQ,为什么我会收到诸如java.net.SocketException之类的错误:权限被拒绝:使用JDK7连接到我的邮件服务器时连接。

Set the System property "java.net.preferIPv4Stack" to "true".

将System属性“java.net.preferIPv4Stack”设置为“true”。