I am trying to send emails from a development computer running Tomcat on Apache. I am developing on Windows but others are developing on Macintosh or 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.