Search in sources :

Example 1 with Content

use of software.amazon.awssdk.services.ses.model.Content in project aws-doc-sdk-examples by awsdocs.

the class SendEmail method sendMsg.

public void sendMsg(Set<String> unqiueKeys) {
    Region region = Region.US_EAST_1;
    SesClient client = SesClient.builder().region(region).build();
    String sender = "<Enter the sender email address>";
    String recipient = "<Enter the recipient email address>";
    // Set the HTML body.
    String bodyHTML = "<html> <head></head> <body><p> The following images contains PPE gear " + "<ol> ";
    // Persist the data into a DynamoDB table.
    for (String myKey : unqiueKeys) {
        bodyHTML = bodyHTML + "<li> " + myKey + "</li>";
    }
    bodyHTML = bodyHTML + "</ol></p></body></html>";
    Destination destination = Destination.builder().toAddresses(recipient).build();
    Content content = Content.builder().data(bodyHTML).build();
    Content sub = Content.builder().data("PPE Information").build();
    Body body = Body.builder().html(content).build();
    Message msg = Message.builder().subject(sub).body(body).build();
    SendEmailRequest emailRequest = SendEmailRequest.builder().destination(destination).message(msg).source(sender).build();
    try {
        System.out.println("Attempting to send an email through Amazon SES " + "using the AWS SDK for Java...");
        client.sendEmail(emailRequest);
    } catch (SesException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : Destination(software.amazon.awssdk.services.ses.model.Destination) Message(software.amazon.awssdk.services.ses.model.Message) Content(software.amazon.awssdk.services.ses.model.Content) SesClient(software.amazon.awssdk.services.ses.SesClient) Region(software.amazon.awssdk.regions.Region) SesException(software.amazon.awssdk.services.ses.model.SesException) Body(software.amazon.awssdk.services.ses.model.Body) SendEmailRequest(software.amazon.awssdk.services.ses.model.SendEmailRequest)

Aggregations

Region (software.amazon.awssdk.regions.Region)1 SesClient (software.amazon.awssdk.services.ses.SesClient)1 Body (software.amazon.awssdk.services.ses.model.Body)1 Content (software.amazon.awssdk.services.ses.model.Content)1 Destination (software.amazon.awssdk.services.ses.model.Destination)1 Message (software.amazon.awssdk.services.ses.model.Message)1 SendEmailRequest (software.amazon.awssdk.services.ses.model.SendEmailRequest)1 SesException (software.amazon.awssdk.services.ses.model.SesException)1