使用smtp java发送带有Amazon SES的电子邮件

时间:2018-05-02 11:04:13

标签: java amazon-web-services amazon-ses

我正在尝试使用与此处完全相同的代码:https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-using-smtp-java.html我更改了FROM, FROMNAME, TO, SMTP_USERNAME, SMTP_PASSWORD, HOST。但我无法发送电子邮件。这两封电子邮件都已针对Amazon SES添加并验证。

我正在使用邮件依赖:

    <dependency>
        <groupId>com.sun.mail</groupId>
        <artifactId>javax.mail</artifactId>
        <version>1.6.1</version>
    </dependency>

日志:

DEBUG: JavaMail version 1.6.1
DEBUG: URL jar:file:/C:/Users/ranjans/.m2/repository/com/amazonaws/aws-java-sdk-ses/1.10.5.1/aws-java-sdk-ses-1.10.5.1.jar!/META-INF/javamail.providers
DEBUG: successfully loaded resource: jar:file:/C:/Users/ranjans/.m2/repository/com/amazonaws/aws-java-sdk-ses/1.10.5.1/aws-java-sdk-ses-1.10.5.1.jar!/META-INF/javamail.providers
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle], com.amazonaws.services.simpleemail.AWSJavaMailTransport=javax.mail.Provider[TRANSPORT,aws,com.amazonaws.services.simpleemail.AWSJavaMailTransport,Amazon Web Services LLC]}
DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle], aws=javax.mail.Provider[TRANSPORT,aws,com.amazonaws.services.simpleemail.AWSJavaMailTransport,Amazon Web Services LLC]}
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
Sending...
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "email-smtp.us-east-1.amazonaws.com", port 587, isSSL false
The email was not sent.
Error message: Couldn't connect to host, port: email-smtp.us-east-1.amazonaws.com, 587; timeout -1

问题出在哪里?

2 个答案:

答案 0 :(得分:0)

  

尝试连接主机“email-smtp.us-east-1.amazonaws.com”,端口 587 ,isSSL false

     

电子邮件未发送。

你应该尝试端口25,如果isSSL = false或者使SSL = true并使用ssl端口。

答案 1 :(得分:0)

检查防火墙/防病毒设置。