2014-02-27 10 views
1

http://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-using-sdk-java.html에는 AWS-SES를 통해 이메일을 보내는 방법에 대한 설명이 있습니다. access_key W secret_key를 나타냄니다. 하지만 내가 가지고있는 것은 포털에서 생성 한 SMTP 사용자 이름과 SMTP 암호입니다.AWS SES의 자격 증명

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

AmazonSimpleEmailServiceClient의 생성자가 AWSCredentials 아니라 SMTP 자격 증명을 취 다음과 같이

현재 내 코드입니다. SMTP 자격 증명을 사용하는 방법에 대한 아이디어가 있습니까?

답변

0

Amazon SES SMTP의 전송으로 JavaMail을 사용하십시오. SMTP 끝점 사용을위한 Instructions and sample code은 Amazon SES 설명서에서도 제공됩니다.

Amazon SES API를 통해 이메일을 보내려는 경우 SDK를 사용하십시오.

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(); 
     }