public final class EmailRequestBuilder
extends java.lang.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 and Description |
|---|
EmailRequestBuilder()
Create a new instance of the builder.
|
| Modifier and Type | Method and Description |
|---|---|
EmailRequestBuilder |
addAttachment(Attachment attachment)
Adds an attachment to the message.
|
EmailRequestBuilder |
addHeader(java.lang.String key,
java.lang.String value)
Add a custom header to the email message.
|
byte[] |
toByteArray()
Creates a byte array containing the MIME encoded raw message for the email.
|
java.nio.ByteBuffer |
toByteBuffer()
Creates a
ByteBuffer containing the MIME encoded raw message for the email. |
java.lang.String |
toString()
Generates the MIME encoded string for the message.
|
EmailRequestBuilder |
withBccAddresses(java.lang.String... addresses)
Set the list of addresses to be copied on the message without other recipients being
aware.
|
EmailRequestBuilder |
withCcAddresses(java.lang.String... addresses)
Set the list of addresses to be copied on the message.
|
EmailRequestBuilder |
withConfigSet(java.lang.String configSet)
Specifies an SES configuration set to use for the message.
|
EmailRequestBuilder |
withFromAddress(java.lang.String address)
Set the source or from address of the message.
|
EmailRequestBuilder |
withFromArn(java.lang.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.
|
EmailRequestBuilder |
withHtmlBody(java.lang.String body)
Sets the body of the message using a content type of
text/html. |
EmailRequestBuilder |
withReplyToAddresses(java.lang.String... addresses)
Set the list of addresses to use for replies to the message.
|
EmailRequestBuilder |
withSubject(java.lang.String subject)
Sets the subject of the message.
|
EmailRequestBuilder |
withTextBody(java.lang.String body)
Sets the body of the message using a content type of
text/plain. |
EmailRequestBuilder |
withToAddresses(java.lang.String... addresses)
Set the list of recipients for the message.
|
public EmailRequestBuilder()
public EmailRequestBuilder withFromAddress(java.lang.String address)
SendRawEmailRequest object.public EmailRequestBuilder withFromArn(java.lang.String fromArn)
X-SES-FROM-ARN header.public EmailRequestBuilder withToAddresses(java.lang.String... addresses)
public EmailRequestBuilder withReplyToAddresses(java.lang.String... addresses)
public EmailRequestBuilder withCcAddresses(java.lang.String... addresses)
public EmailRequestBuilder withBccAddresses(java.lang.String... addresses)
public EmailRequestBuilder addHeader(java.lang.String key, java.lang.String value)
public EmailRequestBuilder withConfigSet(java.lang.String configSet)
public EmailRequestBuilder withSubject(java.lang.String subject)
public EmailRequestBuilder withHtmlBody(java.lang.String body)
text/html.public EmailRequestBuilder withTextBody(java.lang.String body)
text/plain.public EmailRequestBuilder addAttachment(Attachment attachment)
public java.nio.ByteBuffer toByteBuffer()
ByteBuffer containing the MIME encoded raw message for the email.public byte[] toByteArray()
public java.lang.String toString()
toString in class java.lang.Object