Package com.netflix.iep.ses
Class EmailRequestBuilder
java.lang.Object
com.netflix.iep.ses.EmailRequestBuilder
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddAttachment(Attachment attachment) Adds an attachment to the message.Add a custom header to the email message.byte[]Creates a byte array containing the MIME encoded raw message for the email.Creates aByteBuffercontaining the MIME encoded raw message for the email.toString()Generates the MIME encoded string for the message.withBccAddresses(String... addresses) Set the list of addresses to be copied on the message without other recipients being aware.withCcAddresses(String... addresses) Set the list of addresses to be copied on the message.withConfigSet(String configSet) Specifies an SES configuration set to use for the message.withFromAddress(String address) Set the source or from address of the message.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.withHtmlBody(String body) Sets the body of the message using a content type oftext/html.withReplyToAddresses(String... addresses) Set the list of addresses to use for replies to the message.withSubject(String subject) Sets the subject of the message.withTextBody(String body) Sets the body of the message using a content type oftext/plain.withToAddresses(String... addresses) Set the list of recipients for the message.
-
Constructor Details
-
EmailRequestBuilder
public EmailRequestBuilder()Create a new instance of the builder.
-
-
Method Details
-
withFromAddress
Set the source or from address of the message. If not specified, then it must be provided when constructing theSendRawEmailRequestobject. -
withFromArn
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 theX-SES-FROM-ARNheader. -
withToAddresses
Set the list of recipients for the message. -
withReplyToAddresses
Set the list of addresses to use for replies to the message. -
withCcAddresses
Set the list of addresses to be copied on the message. -
withBccAddresses
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
Add a custom header to the email message. -
withConfigSet
Specifies an SES configuration set to use for the message.- See Also:
-
withSubject
Sets the subject of the message. This field is required. -
withHtmlBody
Sets the body of the message using a content type oftext/html. -
withTextBody
Sets the body of the message using a content type oftext/plain. -
addAttachment
Adds an attachment to the message. -
toByteBuffer
Creates aByteBuffercontaining 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
Generates the MIME encoded string for the message.
-