【发布时间】:2021-06-15 02:48:17
【问题描述】:
在下面的代码中我尝试了 2 种组合
- 用户(参考附图),密码
- 访问 ID 和访问密钥
两者都给出了相同的错误。我在家庭网络的 eclipse 环境中运行了这段代码。
错误
Attempting to send an email through the Amazon SES SMTP interface...
The email was not sent.
Error message: 535 Authentication Credentials Invalid
代码
public class amazon_ses_smtp_test {
static final String FROM = "someone@myemail.com"; // This has been verified on the Amazon SES setup
static final String TO = "justanyone@anydomain"; // I have production access
static final String BODY = "This email was sent through the Amazon SES SMTP interface by using Java.";
static final String SUBJECT = "Amazon SES test (SMTP interface accessed using Java)";
static final String SMTP_USERNAME = "tried username and tried accesskey here";
static final String SMTP_PASSWORD = "tried the password and the access key";
static final String HOST = "email-smtp.us-east-1.amazonaws.com";
static final int PORT = 25;
public static void main(String[] args) throws Exception {
Properties props = System.getProperties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.port", PORT);
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.starttls.required", "true");
Session session = Session.getDefaultInstance(props);
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(FROM));
msg.setRecipient(Message.RecipientType.TO, new InternetAddress(TO));
msg.setSubject(SUBJECT);
msg.setContent(BODY,"text/plain");
Transport transport = session.getTransport();
try
{
System.out.println("Attempting to send an email through the Amazon SES SMTP interface...");
transport.connect(HOST, SMTP_USERNAME, SMTP_PASSWORD);
transport.sendMessage(msg, msg.getAllRecipients());
System.out.println("Email sent!");
}
catch (Exception ex) {
System.out.println("The email was not sent.");
System.out.println("Error message: " + ex.getMessage());
}
finally
{
transport.close();
}
}
}
【问题讨论】:
-
我认为你不能使用 25 端口
-
我已经在这里尝试了所有答案,但到目前为止对我没有任何效果
-
查看 AWS 文档,他们彻底改变了事情,而无需打扰开发人员。
-
也不清楚你试过什么。
标签: amazon-ses