我已经一遍又一遍地验证了来自和发送到电子邮件地址(两封电子邮件都区分大小写)我仍然收到 554 消息被拒绝:电子邮件地址未验证 SES 拒绝。但是,当我尝试使用相同的电子邮件从 Amazon SES 控制台发送电子邮件时,它工作正常。如果我的来往电子邮件未经验证,那么从控制台也应该不起作用。无法理解发生了什么。
public class AmazonSESSample {
static final String FROM = "from email";
static final String TO = "to email";
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)";
// Supply your SMTP credentials below. Note that your SMTP credentials are different from your AWS credentials.
static final String SMTP_USERNAME = "SMTP USER NAME";
static final String SMTP_PASSWORD = "SMTP PWD";
static final String HOST = "email-smtp.us-east-1.amazonaws.com";
// Port we will connect to on the Amazon SES SMTP endpoint. We are choosing port 25 because we will use
// STARTTLS to encrypt the connection.
static final int PORT = 25;
public static void main(String[] args) throws Exception {
// Create a Properties object to contain connection configuration information.
Properties props = System.getProperties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.port", PORT);
// Set properties indicating that we want to use STARTTLS to encrypt the connection.
// The SMTP session will begin on an unencrypted connection, and then the client
// will issue a STARTTLS command to upgrade to an encrypted connection.
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.starttls.required", "true");
// Create a Session object to represent a mail session with the specified properties.
Session session = Session.getDefaultInstance(props);
// Create a message with the specified information.
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");
// Create a transport.
Transport transport = session.getTransport();
// Send the message.
try
{
System.out.println("Attempting to send an email through the Amazon SES SMTP interface...");
// Connect to Amazon SES using the SMTP username and password you specified above.
transport.connect(HOST, SMTP_USERNAME, SMTP_PASSWORD);
// Send the email.
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());
ex.printStackTrace();
}
finally
{
// Close and terminate the connection.
transport.close();
}
}
}
我遇到了同样的问题,结果证明这是一个简单的盲复制粘贴问题。目前,有 3 个区域使用 SES。根据您设置 ID 的区域,必须相应地修改 HOST 变量。
static final String HOST = "email-smtp.us-east-1.amazonaws.com";
这解决了我的问题。之后,如果要向未经验证的电子邮件地址发送电子邮件,则必须将设置移出沙盒。
http://docs.aws.amazon.com/ses/latest/DeveloperGuide/request-production-access.html
这是您第一次在 SES 中使用此帐户吗?如果是这样,那么您必须处于沙盒模式
如果您的账户仍在沙盒中,您还必须验证除 Amazon SES 邮箱模拟器提供的收件人之外的每个收件人电子邮件地址。
SES 文档
您可以按照以下步骤操作:
1 登录到 AWS 管理控制台。
2 转到 SES 发送限制提高。
3 填写所需的详细信息并将限制设置为您想要的用途
移出沙盒