Class EmailRequestBuilder

java.lang.Object
com.netflix.iep.ses.EmailRequestBuilder

public final class EmailRequestBuilder extends Object

Helper for building RawMessage requests for the common case of an HTML or test email message with some attachments. For more details on Amazon's recommendations see sending raw email. With this class the usage is much simpler, e.g. with the v1 SDK:

 AmazonSimpleEmailService client = ...
 RawMessage message = new RawMessage().withData(
   new EmailRequestBuilder()
     .withFromAddress("bob@example.com")
     .withToAddresses("andrew@example.com")
     .withSubject("Test message")
     .withHtmlBody("<html><body><h1>Alert!</h1><p><img src=\"cid:my-image.png\"></p></body></html>")
     .addAttachment(Attachment.fromResource("image/png", "my-image.png"))
     .toByteBuffer()
 );
 client.sendRawEmail(new SendRawEmailRequest().withRawMessage(message));
 

With the v2 SDK:

 SesClient client = SesClient.create();
 SdkBytes data = SdkBytes.fromByteBuffer(
   new EmailRequestBuilder()
     .withFromAddress("bob@example.com")
     .withToAddresses("andrew@example.com")
     .withSubject("Test message")
     .withHtmlBody("<html><body><h1>Alert!</h1><p><img src=\"cid:my-image.png\"></p></body></html>")
     .addAttachment(Attachment.fromResource("image/png", "my-image.png"))
     .toByteBuffer()
 );
 SendRawEmailRequest request = SendRawEmailRequest.builder()
   .rawMessage(RawMessage.builder().data(data).build())
   .build();
 client.sendRawEmail(request);
 
  • Constructor Details

    • EmailRequestBuilder

      public EmailRequestBuilder()
      Create a new instance of the builder.
  • Method Details

    • withFromAddress

      public EmailRequestBuilder withFromAddress(String address)
      Set the source or from address of the message. If not specified, then it must be provided when constructing the SendRawEmailRequest object.
    • withFromArn

      public EmailRequestBuilder withFromArn(String fromArn)
      Set the ARN of the identity that is associated with the sending authorization policy that permits you to specify a particular "From" address in the header of the raw email. The ARN will be encoded in the message with the X-SES-FROM-ARN header.
    • withToAddresses

      public EmailRequestBuilder withToAddresses(String... addresses)
      Set the list of recipients for the message.
    • withReplyToAddresses

      public EmailRequestBuilder withReplyToAddresses(String... addresses)
      Set the list of addresses to use for replies to the message.
    • withCcAddresses

      public EmailRequestBuilder withCcAddresses(String... addresses)
      Set the list of addresses to be copied on the message.
    • withBccAddresses

      public EmailRequestBuilder withBccAddresses(String... addresses)
      Set the list of addresses to be copied on the message without other recipients being aware. This can be useful for privacy as well as minimizing spam for notification messages if other recipients are likely to be uninterested in the replies (many have a habit of reply all).
    • addHeader

      public EmailRequestBuilder addHeader(String key, String value)
      Add a custom header to the email message.
    • withConfigSet

      public EmailRequestBuilder withConfigSet(String configSet)
      Specifies an SES configuration set to use for the message.
      See Also:
    • withSubject

      public EmailRequestBuilder withSubject(String subject)
      Sets the subject of the message. This field is required.
    • withHtmlBody

      public EmailRequestBuilder withHtmlBody(String body)
      Sets the body of the message using a content type of text/html.
    • withTextBody

      public EmailRequestBuilder withTextBody(String body)
      Sets the body of the message using a content type of text/plain.
    • addAttachment

      public EmailRequestBuilder addAttachment(Attachment attachment)
      Adds an attachment to the message.
    • toByteBuffer

      public ByteBuffer toByteBuffer()
      Creates a ByteBuffer containing the MIME encoded raw message for the email.
    • toByteArray

      public byte[] toByteArray()
      Creates a byte array containing the MIME encoded raw message for the email.
    • toString

      public String toString()
      Generates the MIME encoded string for the message.
      Overrides:
      toString in class Object