java - 试过 tjavax.mail.MessagingException : Unknown SMTP host: "smtp.office365.com";

标签 java ubuntu amazon-web-services smtp

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

我已经尝试将 SMTP 服务器更改为 smtp.live.comsmtp-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";

最佳答案

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

挖掘 email-smtp.eu-west-1.amazonaws.com

你得到了什么。据我所知,这可能是 DNS 问题。

关于java - 试过 tjavax.mail.MessagingException : Unknown SMTP host: "smtp.office365.com";,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32228696/

相关文章:

Java 泛型 : actual argument T cannot be converted to int by method invocation conversion

mongodb - 升级mongodb没有效果仍然显示旧版本

amazon-web-services - AWS批处理 - 如何限制并发作业的数量

amazon-web-services - 仅保留从 API 网关到 Lambda 的正文

asp.net-mvc - 使用 AWS .NET SDK 确认 SNS 订阅的示例

java - 为什么没有找到休息终点?

java - 使用 Ant 构建一个包含 ActionbarSherlock 作为库项目的项目

java - XMLEncoder 和 PersistenceDelegate

node.js - Node 未启动

Laravel Sail 在 Ubuntu 20.04 LTS 中无法正常工作