Example usage for com.amazonaws.services.simpleemail.model Message getBody

List of usage examples for com.amazonaws.services.simpleemail.model Message getBody

Introduction

In this page you can find the example usage for com.amazonaws.services.simpleemail.model Message getBody.

Prototype


public Body getBody() 

Source Link

Document

The message body.

Usage

From source file:com.kolich.aws.services.ses.impl.KolichSESClient.java

License:Open Source License

@Override
public Either<HttpFailure, SendEmailResult> sendEmail(final Destination destination, final Message message,
        final List<String> replyToAddresses, final String returnPath, final String from) {
    return new AwsSESHttpClosure<SendEmailResult>(client_, SC_OK, new SendEmailResultStaxUnmarshaller()) {
        @Override//  w  ww. j  a  v a  2 s . co m
        public void validate() throws Exception {
            checkNotNull(destination, "Destination cannot be null.");
            checkNotNull(message, "Message cannot be null.");
            checkNotNull(from, "From email address cannot be null.");
            checkState(isValidEmail(from),
                    "Invalid 'from' email address, " + "did not match expected email pattern.");
        }

        @Override
        public void prepare(final AwsHttpRequest request) throws Exception {
            request.addParameter(SES_ACTION_PARAM, SES_ACTION_SENDEMAIL);
            request.addParameter(SES_SOURCE_ADDRESS_PARAM, from);
            // To
            for (int i = 0; i < destination.getToAddresses().size(); i++) {
                final String to = destination.getToAddresses().get(i);
                request.addParameterOpt(String.format("%s.%s", SES_DESTINATION_TO_PARAM, i + 1), to);
            }
            // CC
            for (int i = 0; i < destination.getCcAddresses().size(); i++) {
                final String cc = destination.getCcAddresses().get(i);
                request.addParameterOpt(String.format("%s.%s", SES_DESTINATION_CC_PARAM, i + 1), cc);
            }
            // BCC
            for (int i = 0; i < destination.getBccAddresses().size(); i++) {
                final String bcc = destination.getBccAddresses().get(i);
                request.addParameterOpt(String.format("%s.%s", SES_DESTINATION_BCC_PARAM, i + 1), bcc);
            }
            // Subject
            final Content subject;
            if ((subject = message.getSubject()) != null) {
                request.addParameterOpt(SES_SUBJECT_PARAM, subject.getData());
                request.addParameterOpt(SES_SUBJECT_CHARSET_PARAM, subject.getCharset());
            }
            // Body
            final Body body;
            if ((body = message.getBody()) != null) {
                // Text body
                final Content text;
                if ((text = body.getText()) != null) {
                    request.addParameterOpt(SES_BODY_TEXT_PARAM, text.getData());
                    request.addParameterOpt(SES_BODY_TEXT_CHARSET_PARAM, text.getCharset());
                }
                final Content html;
                if ((html = body.getHtml()) != null) {
                    request.addParameterOpt(SES_BODY_HTML_PARAM, html.getData());
                    request.addParameterOpt(SES_BODY_HTML_CHARSET_PARAM, html.getCharset());
                }
            }
            // Reply-To
            if (replyToAddresses != null) {
                for (int i = 0; i < replyToAddresses.size(); i++) {
                    final String replyTo = replyToAddresses.get(i);
                    request.addParameterOpt(String.format("%s.%s", SES_REPLY_TO_PARAM, i + 1), replyTo);
                }
            }
            // Return path
            request.addParameterOpt(SES_RETURN_PATH_PARAM, returnPath);
        }
    }.post();
}

From source file:com.netflix.iep.ses.EmailRequestBuilder.java

License:Apache License

/**
 * Sets the main message. Note the charset will be ignored and UTF-8 will get used.
 *
 * @deprecated Use {@link #withSubject(String)} and either {@link #withTextBody(String)}
 * or {@link #withHtmlBody(String)} instead. This allows the builder to be used with either
 * v1 or v2 of the AWS SDK for Java. In iep version 2.0 this method and the explicit dependency
 * on v1 of the AWS SDK will be removed.
 *//*from www .  j a v a  2 s . c  om*/
@Deprecated
public EmailRequestBuilder withMessage(Message message) {
    withSubject(message.getSubject().getData());
    Body body = message.getBody();
    if (body.getHtml() != null) {
        withHtmlBody(body.getHtml().getData());
    } else if (body.getText() != null) {
        withTextBody(body.getText().getData());
    }
    return this;
}