Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tried tjavax.mail.MessagingException: Unknown SMTP host: "smtp.office365.com";

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";
like image 574
Ondrej Tokar Avatar asked Nov 09 '22 06:11

Ondrej Tokar


1 Answers

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.

like image 165
Titi Wangsa bin Damhore Avatar answered Nov 11 '22 22:11

Titi Wangsa bin Damhore