Example usage for com.amazonaws.services.simpleemail.model Body withText

List of usage examples for com.amazonaws.services.simpleemail.model Body withText

Introduction

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

Prototype


public Body withText(Content text) 

Source Link

Document

The content of the message, in text format.

Usage

From source file:com.r573.enfili.common.resource.cloud.aws.ses.SesManager.java

License:Apache License

public void sendEmailToSingleRecipient(String recipient, String subject, String emailContentText,
        String emailContentHtml, String sender) {
    SendEmailRequest request = new SendEmailRequest().withSource(sender);

    List<String> toAddresses = new ArrayList<String>();
    toAddresses.add(recipient);/*from w  ww  . j  a v  a  2s.c om*/
    Destination dest = new Destination().withToAddresses(recipient);
    request.setDestination(dest);

    Content subjectContent = new Content().withData(subject);
    Message msg = new Message();
    msg.setSubject(subjectContent);

    Body body = new Body();
    if (emailContentText != null) {
        Content textContent = new Content().withData(emailContentText);
        body.withText(textContent);
    }
    if (emailContentHtml != null) {
        Content htmlContent = new Content().withData(emailContentHtml);
        body.withHtml(htmlContent);
    }

    msg.setBody(body);

    request.setMessage(msg);

    client.sendEmail(request);
}

From source file:com.streamreduce.core.service.EmailServiceImpl.java

License:Apache License

private String internalSendEmail(String to, String from, String replyTo, String subject, String htmlBody,
        String textBody) {//from   w  w w  .j a va 2 s .  c  o m
    SendEmailRequest request = new SendEmailRequest().withSource(from).withReplyToAddresses(replyTo);

    List<String> toAddresses = new ArrayList<>();
    toAddresses.add(to);

    Destination dest = new Destination().withToAddresses(toAddresses);
    request.setDestination(dest);

    Content subjContent = new Content().withData(subject);
    Message msg = new Message().withSubject(subjContent);

    // Include a body in both text and HTML formats
    Body theBody = new Body();
    if (textBody != null) {
        theBody.withText(new Content().withData(textBody));
    }
    if (htmlBody != null) {
        theBody.withHtml(new Content().withData(htmlBody));
    }
    msg.setBody(theBody);

    request.setMessage(msg);

    // Call Amazon SES to send the message
    String messageId = null;
    try {
        SendEmailResult result = simpleEmailServiceClient.sendEmail(request);
        messageId = result.getMessageId();
    } catch (AmazonClientException e) {
        logger.debug("[SES EMAIL] AWS AmazonClientException " + e.getMessage());
        logger.error("Caught an AddressException, which means one or more of your "
                + "addresses are improperly formatted." + e.getMessage());
    } catch (Exception e) {
        logger.debug("[SES EMAIL] AWS General Exception " + e.getMessage());
    }
    return messageId;
}

From source file:uk.co.jassoft.email.EmailSenderService.java

public void send(String recipientAddress, String subject, Map emailContent) throws EmailSendException {
    try {//from w w w.j av  a  2  s.  co  m
        if (System.getenv("API_SEND_EMAILS").equals("false")) {
            LOG.info("API_SEND_EMAILS is set to [{}]", System.getenv("API_SEND_EMAILS"));
            return;
        }

        // Construct an object to contain the recipient address.
        Destination destination = new Destination().withToAddresses(recipientAddress);

        // Create the subject and body of the message.
        Content subjectContent = new Content().withData(subject);

        Body body = new Body();

        if (template != null)
            body = body.withText(new Content().withData(VelocityEngineUtils
                    .mergeTemplateIntoString(velocityEngine, template, "UTF-8", emailContent)));

        if (htmlTemplate != null)
            body = body.withHtml(new Content().withData(VelocityEngineUtils
                    .mergeTemplateIntoString(velocityEngine, htmlTemplate, "UTF-8", emailContent)));

        // Create a message with the specified subject and body.
        Message message = new Message().withSubject(subjectContent).withBody(body);

        // Assemble the email.
        SendEmailRequest request = new SendEmailRequest().withSource(fromAddress).withDestination(destination)
                .withMessage(message);

        AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(
                new EnvironmentVariableCredentialsProvider());
        Region REGION = Region.getRegion(Regions.EU_WEST_1);
        client.setRegion(REGION);

        // Send the email.
        client.sendEmail(request);
    } catch (Exception exception) {
        throw new EmailSendException(exception.getMessage(), exception);
    }
}