Example usage for com.amazonaws.services.simpleemail.model.transform SendEmailResultStaxUnmarshaller SendEmailResultStaxUnmarshaller

List of usage examples for com.amazonaws.services.simpleemail.model.transform SendEmailResultStaxUnmarshaller SendEmailResultStaxUnmarshaller

Introduction

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

Prototype

SendEmailResultStaxUnmarshaller

Source Link

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  w  w.  j  ava2  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();
}