javaemailamazon-sesamazon-simple-email-service

AWS SES SMTP AuthenticationFailedException: 220 Ready to start TLS


I followed the instructions in the documentation (https://docs.aws.amazon.com/zh_cn/ses/latest/dg/send-email-smtp.html) to create the SMTP credentials and downloaded the .csv file of the credentials; but When I sent an email using SMTP in Java code (Open JDK 1.8), I received an exception.

my dependencies:

        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>1.4.7</version>
        </dependency>

my code:

private static final String HOST = "email-smtp.us-west-2.amazonaws.com";
    private static final String PORT = "587";
    private static final String USER_NAME = "SMTP user name in credentials.csv";
    private static final String PASSWORD = "SMTP password in credentials.csv";

    public static void main(String[] args) throws UnsupportedEncodingException, MessagingException {
        Properties props = new Properties();
        props.put("mail.smtp.host", HOST);
        props.put("mail.smtp.port", PORT);
        props.put("mail.smtp.auth", "true");
        Session session = Session.getInstance(props, new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(USER_NAME, PASSWORD);
            }
        });

        MimeMessage message = new MimeMessage(session);
        message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("faxon.xing@gmail.com"));
        message.setSubject("AWS SES SMTP Email");
        message.setContent("<p>Hello, AWS SES SMTP<a href=\"https://www.google.com\">click btn</a></p>", "text/html;charset=UTF-8");

        Transport.send(message);
    }

Exception log:Exception in thread "main" javax.mail.AuthenticationFailedException: 220 Ready to start TLS

How should I solve it?


Solution

  • This issue has been resolved

    props.put("mail.smtp.ssl.protocols", "TLSv1.2");