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

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

Introduction

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

Prototype


public void setHtml(Content html) 

Source Link

Document

The content of the message, in HTML format.

Usage

From source file:com.netflix.simianarmy.aws.AWSEmailNotifier.java

License:Apache License

@Override
public void sendEmail(String to, String subject, String body) {
    if (!isValidEmail(to)) {
        LOGGER.error(String.format("The destination email address %s is not valid,  no email is sent.", to));
        return;/*from   w  w  w . j  a  v  a2  s .c  om*/
    }
    if (sesClient == null) {
        String msg = "The email client is not set.";
        LOGGER.error(msg);
        throw new RuntimeException(msg);
    }
    Destination destination = new Destination().withToAddresses(to).withCcAddresses(getCcAddresses(to));
    Content subjectContent = new Content(subject);
    Content bodyContent = new Content();
    Body msgBody = new Body(bodyContent);
    msgBody.setHtml(new Content(body));
    Message msg = new Message(subjectContent, msgBody);
    String sourceAddress = getSourceAddress(to);
    SendEmailRequest request = new SendEmailRequest(sourceAddress, destination, msg);
    request.setReturnPath(sourceAddress);
    LOGGER.debug(String.format("Sending email with subject '%s' to %s", subject, to));
    SendEmailResult result = null;
    try {
        result = sesClient.sendEmail(request);
    } catch (Exception e) {
        throw new RuntimeException(String.format("Failed to send email to %s", to), e);
    }
    LOGGER.info(
            String.format("Email to %s, result id is %s, subject is %s", to, result.getMessageId(), subject));
}

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

License:Apache License

/**
 * Send email.//from   w  w  w. j  av  a  2  s  . c o 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:org.openchain.certification.utility.EmailUtility.java

License:Apache License

public static void emailVerification(String name, String email, UUID uuid, String username,
        String responseServletUrl, ServletConfig config) throws EmailUtilException {
    String fromEmail = config.getServletContext().getInitParameter("return_email");
    if (fromEmail == null || fromEmail.isEmpty()) {
        logger.error("Missing return_email parameter in the web.xml file");
        throw (new EmailUtilException(
                "The from email for the email facility has not been set.  Pleaese contact the OpenChain team with this error."));
    }/*from ww  w  .  j a  va  2  s. co m*/
    String link = responseServletUrl + "?request=register&username=" + username + "&uuid=" + uuid.toString();
    StringBuilder msg = new StringBuilder("<div>Welcome ");
    msg.append(name);
    msg.append(
            " to the OpenChain Certification website.<br /> <br />To complete your registration, click on the following or copy/paste into your web browser <a href=\"");
    msg.append(link);
    msg.append("\">");
    msg.append(link);
    msg.append("</a><br/><br/>Thanks,<br/>The OpenChain team</div>");
    Destination destination = new Destination().withToAddresses(new String[] { email });
    Content subject = new Content().withData("OpenChain Registration [do not reply]");
    Content bodyData = new Content().withData(msg.toString());
    Body body = new Body();
    body.setHtml(bodyData);
    Message message = new Message().withSubject(subject).withBody(body);
    SendEmailRequest request = new SendEmailRequest().withSource(fromEmail).withDestination(destination)
            .withMessage(message);
    try {
        AmazonSimpleEmailServiceClient client = getEmailClient(config);
        client.sendEmail(request);
        logger.info("Invitation email sent to " + email);
    } catch (Exception ex) {
        logger.error("Email send failed", ex);
        throw (new EmailUtilException("Exception occured during the emailing of the invitation", ex));
    }
}

From source file:org.openchain.certification.utility.EmailUtility.java

License:Apache License

public static void emailAdmin(String subjectText, String msg, ServletConfig config) throws EmailUtilException {
    String fromEmail = config.getServletContext().getInitParameter("return_email");
    if (fromEmail == null || fromEmail.isEmpty()) {
        logger.error("Missing return_email parameter in the web.xml file");
        throw (new EmailUtilException(
                "The from email for the email facility has not been set.  Pleaese contact the OpenChain team with this error."));
    }//from  ww w .j av a  2s.com
    String toEmail = config.getServletContext().getInitParameter("notification_email");
    if (toEmail == null || toEmail.isEmpty()) {
        logger.error("Missing notification_email parameter in the web.xml file");
        throw (new EmailUtilException(
                "The to email for the email facility has not been set.  Pleaese contact the OpenChain team with this error."));
    }

    Destination destination = new Destination().withToAddresses(new String[] { toEmail });
    Content subject = new Content().withData(subjectText);
    Content bodyData = new Content().withData(msg.toString());
    Body body = new Body();
    body.setHtml(bodyData);
    Message message = new Message().withSubject(subject).withBody(body);
    SendEmailRequest request = new SendEmailRequest().withSource(fromEmail).withDestination(destination)
            .withMessage(message);
    try {
        AmazonSimpleEmailServiceClient client = getEmailClient(config);
        client.sendEmail(request);
        logger.info("Admin email sent to " + toEmail + ": " + msg);
    } catch (Exception ex) {
        logger.error("Email send failed", ex);
        throw (new EmailUtilException("Exception occured during the emailing of the submission notification",
                ex));
    }
}

From source file:org.openchain.certification.utility.EmailUtility.java

License:Apache License

/**
 * Email to notify a user that their profiles was updated
 * @param username// www  .  ja va 2s.c om
 * @param email
 * @param config
 * @throws EmailUtilException
 */
public static void emailProfileUpdate(String username, String email, ServletConfig config)
        throws EmailUtilException {
    String fromEmail = config.getServletContext().getInitParameter("return_email");
    if (fromEmail == null || fromEmail.isEmpty()) {
        logger.error("Missing return_email parameter in the web.xml file");
        throw (new EmailUtilException(
                "The from email for the email facility has not been set.  Pleaese contact the OpenChain team with this error."));
    }
    StringBuilder msg = new StringBuilder("<div>The profile for username ");

    msg.append(username);
    msg.append(
            " has been updated.  If you this update has been made in error, please contact the OpenChain certification team.");
    Destination destination = new Destination().withToAddresses(new String[] { email });
    Content subject = new Content().withData("OpenChain Certification profile updated [do not reply]");
    Content bodyData = new Content().withData(msg.toString());
    Body body = new Body();
    body.setHtml(bodyData);
    Message message = new Message().withSubject(subject).withBody(body);
    SendEmailRequest request = new SendEmailRequest().withSource(fromEmail).withDestination(destination)
            .withMessage(message);
    try {
        AmazonSimpleEmailServiceClient client = getEmailClient(config);
        client.sendEmail(request);
        logger.info("Notification email sent for " + email);
    } catch (Exception ex) {
        logger.error("Email send failed", ex);
        throw (new EmailUtilException("Exception occured during the emailing of the submission notification",
                ex));
    }
}

From source file:org.openchain.certification.utility.EmailUtility.java

License:Apache License

public static void emailPasswordReset(String name, String email, UUID uuid, String username,
        String responseServletUrl, ServletConfig config) throws EmailUtilException {
    String fromEmail = config.getServletContext().getInitParameter("return_email");
    if (fromEmail == null || fromEmail.isEmpty()) {
        logger.error("Missing return_email parameter in the web.xml file");
        throw (new EmailUtilException(
                "The from email for the email facility has not been set.  Pleaese contact the OpenChain team with this error."));
    }/*from  w w w .  ja v  a2s  . co m*/
    String link = responseServletUrl + "?request=pwreset&username=" + username + "&uuid=" + uuid.toString();
    StringBuilder msg = new StringBuilder(
            "<div>To reset the your password, click on the following or copy/paste into your web browser <a href=\"");
    msg.append(link);
    msg.append("\">");
    msg.append(link);
    msg.append("</a><br/><br/><br/>The OpenChain team</div>");
    Destination destination = new Destination().withToAddresses(new String[] { email });
    Content subject = new Content().withData("OpenChain Password Reset [do not reply]");
    Content bodyData = new Content().withData(msg.toString());
    Body body = new Body();
    body.setHtml(bodyData);
    Message message = new Message().withSubject(subject).withBody(body);
    SendEmailRequest request = new SendEmailRequest().withSource(fromEmail).withDestination(destination)
            .withMessage(message);
    try {
        AmazonSimpleEmailServiceClient client = getEmailClient(config);
        client.sendEmail(request);
        logger.info("Reset password email sent to " + email);
    } catch (Exception ex) {
        logger.error("Email send failed", ex);
        throw (new EmailUtilException("Exception occured during the emailing of the password reset", ex));
    }
}