I am getting this error when I try to send an email from Java web app hosted on AWS.
I have already tried to change SMTP server to smtp.live.com
and also smtp-mail.outlook.com
, none of those work.
Can it be some AWS config? It runs on Ubuntu. (There are no outbound restrictions on the server itself, there might be some on Java server though)
Code for sending the email:
final String username = smtpUsername;
final String password = smtpPwd;
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", smtpHost);
props.put("mail.smtp.port", smtpPort);
Session session = Session.getInstance(props, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(smtpUsername));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(sendTo));
message.setSubject(subject);
message.setContent(content);
Transport.send(message);
System.out.println("Sent");
} catch (MessagingException e) {
e.printStackTrace();
}
The most interesting part of this is, that it works from my local computer...(but only when I disable Avast)
I have tried to execute telnet smtp.office365.com 587
and the result was:
Trying 132.245.195.162...
Connected to outlook-emeawest2.office365.com.
Escape character is '^]'.
220 HE1PR08CA0021.outlook.office365.com Microsoft ESMTP MAIL Service ready at Wed, 26 Aug 2015 14:32:11 +0000
I have tried to set up the AWS SMTP (SES
) and I am getting the same error, even after I followed the documentation, I also added the email from which I was sending and to which I was sending to the verified emails (whitelist):
javax.mail.MessagingException: Unknown SMTP host: "email-smtp.eu-west-1.amazonaws.com";
try doing a dig from a bash shell from the ubuntu machine
dig email-smtp.eu-west-1.amazonaws.com
what are you getting. from what I can see, it might be a DNS problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With