Java Code Examples for com.amazonaws.services.simpleemail.model.SendEmailRequest#setDestination()

The following examples show how to use com.amazonaws.services.simpleemail.model.SendEmailRequest#setDestination() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EmailService.java    From oneops with Apache License 2.0 6 votes vote down vote up
/**
 * Send email.
 *
 * @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;
}
 
Example 2
Source File: SesDaoImpl.java    From herd with Apache License 2.0 6 votes vote down vote up
/**
 * Prepares a {@link SendEmailRequest} with information harvested from emailSendRequest
 *
 * @param emailSendRequest the specified email information.
 *
 * @return the prepared send email request.
 */
private SendEmailRequest prepareSendEmailRequest(EmailSendRequest emailSendRequest)
{
    // Collect all required information and prepare individual email components required for the desired send email request.
    // Initialize a new aws send email request.
    SendEmailRequest sendEmailRequest = new SendEmailRequest();

    // Set 'from' address to the configured 'send-from' email address.
    sendEmailRequest.setSource(emailSendRequest.getSource());

    // Get destination information and add to send email request
    Destination destination = prepareDestination(emailSendRequest);
    sendEmailRequest.setDestination(destination);

    // Get message information and add to send email request
    Message message = prepareMessage(emailSendRequest);
    sendEmailRequest.setMessage(message);

    // Get config set name and add to send email request
    ConfigurationSet configurationSet = new ConfigurationSet().withName(configurationHelper.getProperty(ConfigurationValue.SES_CONFIGURATION_SET_NAME));

    sendEmailRequest.setConfigurationSetName(configurationSet.getName());

    return sendEmailRequest;
}