AWS SES上的凭据

时间:2014-02-27 09:31:30

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

http://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-using-sdk-java.html中,有关于如何通过AWS-SES发送电子邮件的说明。它指的是access_key和secret_key。但我所拥有的是我在门户网站上生成的SMTP用户名和SMTP密码。

目前我的代码如下:

AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(credentials);
client.sendEmail(request);

AmazonSimpleEmailServiceClient的构造函数采用AWSCredentials而不是smtp凭据。有关如何使用SMTP凭据的任何想法吗?

2 个答案:

答案 0 :(得分:0)

使用JavaMail作为Amazon SES SMTP的传输。 Amazon SES文档中还提供了使用SMTP端点的Instructions and sample code

如果您打算通过Amazon SES API发送电子邮件,请使用SDK。

答案 1 :(得分:0)

You can use below code to send mail through SMTP 

 InternetAddress[] parse = InternetAddress.parse(toAddess , true);

        Properties props = System.getProperties();
        //Add properties
        props.put("mail.transport.protocol", "smtps");
        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");

        // Create a Session object to represent a mail session with the specified properties.
        Session session = Session.getDefaultInstance(props);

        // Create a message with the specified information.
        MimeMessage msg = new MimeMessage(session);

        msg.setFrom(new InternetAddress(fromemail));


        msg.setRecipients(javax.mail.Message.RecipientType.TO,  parse);


        msg.setSubject(subject);
        msg.setContent(body,"text/html");

        // Create a transport.
        Transport transport = session.getTransport();

        // Send the message.
        try
        {
            logger.info("Attempting to send an email through the Amazon SES SMTP interface to "+toAddess);

            // Connect to Amazon SES using the SMTP username and password specified above.
            transport.connect(smtpHost, port, smtpuserName, smtpPassword);


            // Send the email.
            transport.sendMessage(msg, msg.getAllRecipients());
           logger.info("MessageID"+ msg.getMessageID());

            logger.info("Email sent!");
            return msg.getMessageID();
        }
        catch (Exception ex) {
            logger.error("The email was not sent. Error message: " + ex.getMessage());
        }
        finally
        {
            // Close and terminate the connection.
            transport.close();
        }