在下面的代码中,我尝试了2种组合
两者都给出了相同的错误。我在家庭网络中的 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 = "[email protected]"; // 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();
}
}
}
最佳答案
这里是链接:http://docs.aws.amazon.com/ses/latest/DeveloperGuide/smtp-credentials.html
关于amazon-ses - Amazon SES 535身份验证凭证无效,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21452278/