Example usage for com.amazonaws.services.simpleemail.model SendEmailRequest setDestination

List of usage examples for com.amazonaws.services.simpleemail.model SendEmailRequest setDestination

Introduction

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

Prototype


public void setDestination(Destination destination) 

Source Link

Document

The destination for this email, composed of To:, CC:, and BCC: fields.

Usage

From source file:com.erudika.para.email.AWSEmailer.java

License:Apache License

@Override
public boolean sendEmail(List<String> emails, String subject, String body) {
    if (emails != null && !emails.isEmpty() && !StringUtils.isBlank(body)) {
        final SendEmailRequest request = new SendEmailRequest().withSource(Config.SUPPORT_EMAIL);
        Destination dest = new Destination().withToAddresses(emails);
        request.setDestination(dest);

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

        // Include a body in both text and HTML formats
        Content textContent = new Content().withData(body).withCharset(Config.DEFAULT_ENCODING);
        msg.setBody(new Body().withHtml(textContent));

        request.setMessage(msg);/*w  w w  . j  a  va2  s.  c om*/

        Para.asyncExecute(new Runnable() {
            public void run() {
                sesclient.sendEmail(request);
            }
        });
        return true;
    }
    return false;
}

From source file:com.github.trask.sandbox.mail.impl.AmazonMailService.java

License:Apache License

public Future<Void> sendMail(String from, String to, String subject, String htmlBody, String textBody) {

    logger.debug("sendMail(): from={}", from);
    logger.debug("sendMail(): to={}", to);
    logger.debug("sendMail(): subject={}", subject);
    logger.debug("sendMail(): htmlBody={}", htmlBody);
    logger.debug("sendMail(): textBody={}", textBody);

    Body body = new Body(new Content(textBody)).withHtml(new Content(htmlBody));
    Message message = new Message(new Content(subject), body);

    SendEmailRequest sendEmailRequest = new SendEmailRequest();
    sendEmailRequest.setSource(from);//www  .j  a v  a 2  s  .  co m
    sendEmailRequest.setDestination(new Destination(Collections.singletonList(to)));
    sendEmailRequest.setMessage(message);
    Future<SendEmailResult> future = simpleEmailServiceAsync.sendEmailAsync(sendEmailRequest);
    return new VoidFutureWrapper(future);
}

From source file:com.oneops.antenna.senders.aws.EmailService.java

License:Apache License

/**
 * Send email./*ww w. j  a  va2  s  .co m*/
 *
 * @param eMsg the e msg
 * @return true, if successful
 */
public boolean sendEmail(EmailMessage eMsg) {

    SendEmailRequest request = new SendEmailRequest().withSource(eMsg.getFromAddress());
    Destination dest = new Destination().withToAddresses(eMsg.getToAddresses());
    dest.setCcAddresses(eMsg.getToCcAddresses());
    request.setDestination(dest);
    Content subjContent = new Content().withData(eMsg.getSubject());
    Message msg = new Message().withSubject(subjContent);
    Content textContent = new Content().withData(eMsg.getTxtMessage());
    Body body = new Body().withText(textContent);
    if (eMsg.getHtmlMessage() != null) {
        Content htmlContent = new Content().withData(eMsg.getHtmlMessage());
        body.setHtml(htmlContent);
    }
    msg.setBody(body);
    request.setMessage(msg);
    try {
        emailClient.sendEmail(request);
        logger.debug(msg);
    } catch (AmazonClientException e) {
        logger.error(e.getMessage());
        return false;
    }
    return true;
}

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);//w w  w.  j a va2s.c  o  m
    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) {/*  ww  w  .j  a  va 2 s .  co  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:net.smartcosmos.plugin.service.aws.email.AwsEmailService.java

License:Apache License

@Override
public void sendEmail(String to, String subject, String plainMessage, String htmlMessage) {
    String from = context.getConfiguration().getAdminEmailAddress();
    SendEmailRequest request = new SendEmailRequest().withSource(from);

    List<String> toAddresses = new ArrayList<String>();
    toAddresses.add(to);//from   w w w . j a v a 2  s. co m

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

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

    Content textContent = new Content().withData(plainMessage);
    Content htmlContent = new Content().withData(htmlMessage);

    Body body = new Body().withHtml(htmlContent).withText(textContent);
    msg.setBody(body);

    request.setMessage(msg);

    AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(credentials);

    try {
        client.sendEmail(request);
        LOG.info("Registration confirmation sent to email " + to);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.apache.camel.component.aws.ses.SesProducer.java

License:Apache License

private SendEmailRequest createMailRequest(Exchange exchange) {
    SendEmailRequest request = new SendEmailRequest();
    request.setSource(determineFrom(exchange));
    request.setDestination(determineTo(exchange));
    request.setReturnPath(determineReturnPath(exchange));
    request.setReplyToAddresses(determineReplyToAddresses(exchange));
    request.setMessage(createMessage(exchange));

    return request;
}

From source file:org.duracloud.mill.notification.SESNotificationManager.java

License:Apache License

@Override
public void sendEmail(String subject, String body) {
    if (ArrayUtils.isEmpty(this.recipientEmailAddresses)) {
        log.warn("No recipients configured - no one to notify: ignoring...");
        return;//from   w  w  w  .  ja va2s  . c  om
    }

    SendEmailRequest email = new SendEmailRequest();
    try {
        Destination destination = new Destination();
        destination.setToAddresses(Arrays.asList(this.recipientEmailAddresses));
        email.setDestination(destination);
        email.setSource("notifications@duracloud.org");
        Message message = new Message(new Content(subject), new Body(new Content(body)));
        email.setMessage(message);
        client.sendEmail(email);
        log.info("email sent: {}", email);
    } catch (Exception e) {
        log.error("failed to send " + email + ": " + e.getMessage(), e);
    }

}