尝试过tjavax.mail.MessagingException:未知的SMTP主机:“smtp.office365.com”;

时间:2015-08-26 13:56:24

标签: java ubuntu amazon-web-services smtp

当我尝试从AWS上托管的Java Web应用程序发送电子邮件时,我收到此错误。

我已尝试将SMTP服务器更改为smtp.live.com以及smtp-mail.outlook.com,但这些都不起作用。

可以是某些AWS配置吗?它运行在Ubuntu上。 (服务器本身没有出站限制,但Java服务器上可能有一些限制)

发送电子邮件的代码:

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();
    }

最有趣的部分是,它可以在我的本地计算机上运行...(但仅当我禁用Avast时)

我尝试执行telnet smtp.office365.com 587,结果是:

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

我尝试设置AWS SMTP(SES)并且我收到了同样的错误,即使在我按照文档提交后,我还添加了我发送的电子邮件以及我发送的电子邮件已验证的电子邮件(白名单):

javax.mail.MessagingException: Unknown SMTP host: "email-smtp.eu-west-1.amazonaws.com";

1 个答案:

答案 0 :(得分:1)

尝试从ubuntu机器上的bash shell中进行挖掘

dig email-smtp.eu-west-1.amazonaws.com

你得到了什么?从我所看到的,它可能是一个DNS问题。