mercredi 26 août 2015

javax.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...




Aucun commentaire:

Enregistrer un commentaire