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

前端 未结 7 1333
予麋鹿
予麋鹿 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

提交回复
热议问题