【发布时间】:2015-11-20 14:45:57
【问题描述】:
当我尝试从 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";
【问题讨论】:
标签: java ubuntu amazon-web-services smtp