Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/379.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 什么Apache Commons电子邮件服务器在本地主机上工作?_Java_Apache_Localhost - Fatal编程技术网

Java 什么Apache Commons电子邮件服务器在本地主机上工作?

Java 什么Apache Commons电子邮件服务器在本地主机上工作?,java,apache,localhost,Java,Apache,Localhost,我试图从一台在Apache上运行Tomcat的开发计算机发送电子邮件。我在Windows上开发,但其他人在Macintosh或Linux上开发。我无法确定要使用哪个主机和端口。我不知道密码是从哪里来的 public void sendPackage(String toEmailAddress, String subject, String content) { Url url = ((WebRequest)RequestCycle.get().getRequest()).getUrl()

我试图从一台在Apache上运行Tomcat的开发计算机发送电子邮件。我在Windows上开发,但其他人在Macintosh或Linux上开发。我无法确定要使用哪个主机和端口。我不知道密码是从哪里来的

public void sendPackage(String toEmailAddress, String subject, String content)
{
    Url url = ((WebRequest)RequestCycle.get().getRequest()).getUrl();
    String fullUrl = RequestCycle.get().getUrlRenderer().renderFullUrl(url);
    if (fullUrl.toLowerCase().contains("localhost"))
    {
        sHost = "localhost";    //"smtpout.secureserver.net";
        iPort = 465;    //25;   //9090; 
        sFrom = "info@mywebsite.com";
    }
    else
    {
        sHost = "mail.mywebsite.com";
        iPort = 587;
        sFrom = "mail@mywebsite.com";
    }

    try
    {
        Email email = new SimpleEmail();
        email.setDebug(true);
        email.setHostName(sHost);
        email.setSmtpPort(iPort);
        email.setAuthenticator(new DefaultAuthenticator(sFrom, "tuscul312"));
        email.setSSLOnConnect(true);
        email.setFrom(sFrom);
        email.setSubject(subject);
        email.setMsg(content);
        email.addTo(toEmailAddress);
        email.send();
    }
    catch (EmailException eex)
    {
        logger.error("sendPackage failed: " + eex);
        eex.printStackTrace();
    }
}
堆栈跟踪显示

[ERROR] 2018-05-11 17:50:37.096 [http-nio-8080-exec-1] SendEmail - sendPackage failed: org.apache.commons.mail.EmailException: Sending the email to the following server failed : localhost:465
org.apache.commons.mail.EmailException: Sending the email to the following server failed : localhost:465

这个硬编码的配置应该工作吗?
其他地方有服务器设置吗?

好。我刚刚为localhost添加了一个旁路,并将尝试确定服务器需要哪些配置设置。

虽然Windows可能没有本地SMTP服务器,但基于Unix的O/S仍需要SMTP中继。你不能再从任何地方发送到任何地方了——开放SMTP中继的日子早已一去不复返了。不过,你可以使用Gmail——更多细节请参见。
Caused by: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: localhost, 465; timeout 60000;
  nested exception is:
    java.net.ConnectException: Connection refused: connect
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2118)