Could not connect to SMTP host: email-smtp.us-east-1.amazonaws.com, port: 465, response: -1

前端 未结 7 1311
予麋鹿
予麋鹿 2020-12-14 10:36

I am trying to send email with Amazon\'s SES/SMTP and I am getting the following error:

javax.mail.MessagingException: Could not connect to SMTP host: em

相关标签:
7条回答
  • 2020-12-14 11:20
    Properties props = new Properties();
    props.setProperty("mail.transport.protocol", "smtp");
    props.setProperty("mail.smtp.auth", "true");
    props.setProperty("mail.host", "email-smtp.us-east-1.amazonaws.com");
    props.setProperty("mail.user", "your_ses_user");
    props.setProperty("mail.password", "your_ses_pwd");
    
    
    
    Session mailSession = Session.getDefaultInstance(props, new Authenticator(){
        public PasswordAuthentication getPasswordAuthentication() {
            String username = "your_ses_user";
            String password = "your_ses_pwd";
            return new PasswordAuthentication(username, password);
        }
    });
    

    These code have been tested, works fine well. If you want use SMTP over SSL, please config:

    props.setProperty("mail.smtp.starttls.enable", "true");
    

    Or you can download AWS Java SDK from HERE.

    Code sample is HERE

    0 讨论(0)
  • 2020-12-14 11:22

    Note that the AWS note at https://forums.aws.amazon.com/message.jspa?messageID=218303 refers to encrypting server-to-server communication to maintain confidentiality of the email message, is a shared characteristic of all SMTP services.

    This question relates to using a secure connection to the AWS SMTP server to protect the passwords used to authenticate with the AWS server.

    0 讨论(0)
  • 2020-12-14 11:23

    With amazon SES, configuration needs to be as follows:

    <prop key="mail.smtp.auth">true</prop>    
    <prop key="mail.smtp.ssl.enable">true</prop>
    

    instead of:

    <prop key="mail.smtp.auth">true</prop>
    <prop key="mail.smtp.starttls.enable">true</prop> 
    

    as hinted by dave.

    EDIT: Please use this solution: https://stackoverflow.com/a/8928559/536299

    0 讨论(0)
  • 2020-12-14 11:23

    This employee from AWS states that SES does not support SSL at all. https://forums.aws.amazon.com/message.jspa?messageID=218303 .

    Amazon SES will attempt to send email with Transport Layer Security enabled, but there is not a way to guarantee messages are sent with TLS. SES uses opportunistic TLS when sending emails, which means it will attempt to send emails over TLS first, and then will fall back to regular SMTP if TLS is unavailable.

    Hence, I am thinking the issue you are seeing is not TLS or SSL related, rather something else.

    0 讨论(0)
  • 2020-12-14 11:24

    These settings worked for me:

    mail.transport.protocol=smtp
    mail.smtp.port=25
    mail.smtp.auth=true
    mail.smtp.starttls.enable=true
    mail.smtp.starttls.required=true
    mail.smtp.host=email-smtp.us-east-1.amazonaws.com
    mail.smtp.user=[SMTP username]
    mail.smtp.password=[SMTP user password]
    

    If you try to connect to connect using SSL connection, it rejected the connection. So you need to do STARTTLS after connection.

    You can add mail.debug=true to see where it failed.

    The sender email address must be a verified email address otherwise SES refuses to forward the email.

    0 讨论(0)
  • 2020-12-14 11:36

    Amazon SES SMTP requires the SSL before the SMTP session. The StartTLS command is not supported by SES.

    0 讨论(0)
提交回复
热议问题