17 Şubat 2023 Cuma

AWS SES API

Maven
Şu satırı dahil ederiz
<!-- AWS SDK -->
<dependencyManagement>
   <dependencies>
      <dependency>
         <groupId>software.amazon.awssdk</groupId>
         <artifactId>bom</artifactId>
         <version>2.17.282</version>
         <type>pom</type>
         <scope>import</scope>
      </dependency>
   </dependencies>
</dependencyManagement>

<dependencies>
  <!--aws SES-->
  <dependency>
     <groupId>software.amazon.awssdk</groupId>
     <artifactId>ses</artifactId>
  </dependency>
</dependencies>
SesClient Sınıfı
Örnek
Şöyle yaparız
Region region = Region.YOUR_REGION;
SesClient sesClient = SesClient.builder()
        .region(region)
        .credentialsProvider(ProfileCredentialsProvider.create())
        .build();

public void sendEmail(SesClient client, Email email) throws MessagingException {
  Destination destination = Destination.builder()
    .toAddresses(email.getReceiver())
    .build();
  Content content = Content.builder()
    .data(email.getEmailBody())
    .build();
  Content subject = Content.builder()
    .data(email.getSubject())
    .build();
  Body body = Body.builder()
    .html(content)
    .build();
  Message message = Message.builder()
    .subject(subject)
    .body(body)
    .build();
  SendEmailRequest emailRequest = SendEmailRequest.builder()
    .message(message)
    .source(email.getSender())
    .destination(destination)
    .build();
  try {
    client.sendEmail(emailRequest);
  } catch (SesException e) {...}
}



Hiç yorum yok:

Yorum Gönder