У меня есть java-код, который используется для отправки электронной почты по протоколу smtp через порт 587. Я использую javax mail api для этого.Я могу отправлять почту на машины localhost (windows и ubuntu).
Проблема возникает, когда я создал файл war и развернул его на удаленном сервере с ОС Ubuntu. Более того, в журналах нет ошибок.Пожалуйста, помогите, что может быть вероятной причиной и как ее решить.
Вот мой пример кода Spring-Java
public void sendMailForResetPassword(String emailId ) throws AddressException, MessagingException {
EmailDataObject emailproperties=new EmailDataObject();
try {
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", emailproperties.host_name);
props.put("mail.smtp.port", 587);
props.put("mail.smtp.ssl.trust", emailproperties.host_name);
props.put("mail.smtp.UseDefaultCredentials", false);
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication( emailproperties.from, emailproperties.password);
}
});
String link = "www.example.com";
System.out.println("This is best way for forgot password");
StringBuilder bodyText = new StringBuilder();
bodyText.append("<div>")
.append(" Dear User<br/><br/>")
.append(" We got your reset password request, Find below link to reset password <br/>")
.append(" Please click <a href=\""+link+"\">here</a> or open below link in browser<br/>")
.append(" <br/><br/>")
.append("</div>");
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(emailproperties.from));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(emailId));
message.setSubject("Reset Password");
message.setContent(bodyText.toString(), "text/html; charset=utf-8");
session.setDebug(true);
System.out.println(message);
Transport.send(message);
} catch (MessagingException e) {
e.printStackTrace();
}
}
Редактировать
Это вывод session.setDebug (true);
DEBUG SMTP: Found extension "ETRN", arg ""
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "AUTH", arg "PLAIN LOGIN"
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: Found extension "SMTPUTF8", arg ""
STARTTLS 220 2.0.0 Ready to start TLS
EHLO ubuntu-minimal
Спасибо.