可以使用webmail但无法通过javax.mail发送

时间:2022-02-11 15:24:29

I currently have a mail server up and running. I can log into my web-mail client via mywebsite.com/roundcube/

我目前正在启动并运行邮件服务器。我可以通过mywebsite.com/roundcube/登录我的网络邮件客户端

Web-mail allows me to 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. So I can automate e-mails

但是,我真正想做的是使用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?

Edit: Netstat Info

编辑:Netstat信息

myname@mybox:~/Development$ netstat -plnt | grep 25
tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN      -

Edit 2: I'm using Postfix + Courier and based my set-up from http://flurdy.com/docs/postfix/#data

编辑2:我正在使用Postfix + Courier并基于http://flurdy.com/docs/postfix/#data进行设置

1 个解决方案

#1


By default Java preferred IPv6, try set the -Djava.net.preferIPv4Stack=true JVM property to force application to use an IPv4 socket to communicate.

默认情况下,Java首选IPv6,请尝试设置-Djava.net.preferIPv4Stack = true J​​VM属性以强制应用程序使用IPv4套接字进行通信。

#1


By default Java preferred IPv6, try set the -Djava.net.preferIPv4Stack=true JVM property to force application to use an IPv4 socket to communicate.

默认情况下,Java首选IPv6,请尝试设置-Djava.net.preferIPv4Stack = true J​​VM属性以强制应用程序使用IPv4套接字进行通信。