简体   繁体   English

哪些Apache Commons电子邮件服务器可在localhost上运行?

[英]What Apache Commons email server works on localhost?

I am trying to send emails from a development computer running Tomcat on Apache. 我正在尝试从在Apache上运行Tomcat的开发计算机发送电子邮件。 I am developing on Windows but others are developing on Macintosh or Linux. 我在Windows上进行开发,但其他在Macintosh或Linux上进行开发。 I have not been able to determine which host and port to use. 我无法确定要使用的主机和端口。 I do not know where the password came from. 我不知道密码来自哪里。

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();
    }
}

The stack trace showed 堆栈跟踪显示

[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

and

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)

Should this hard-coded configuration work? 这种硬编码配置是否应该起作用? Are there server settings somewhere else? 其他地方是否有服务器设置?

OK. 好。 I have just added a bypass for localhost and will try to determine what configuration settings are required for the server. 我刚刚为localhost添加了一个绕过程序,它将尝试确定服务器所需的配置设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM