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

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

Introduction

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

Prototype

public Body() 

Source Link

Document

Default constructor for Body object.

Usage

From source file:AmazonSESSample.java

License:Open Source License

public static void main(String[] args) throws IOException {

    // Construct an object to contain the recipient address.
    Destination destination = new Destination().withToAddresses(new String[] { TO });

    // Create the subject and body of the message.
    Content subject = new Content().withData(SUBJECT);
    Content textBody = new Content().withData(BODY);
    Body body = new Body().withText(textBody);

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

    // Assemble the email.
    SendEmailRequest request = new SendEmailRequest().withSource(FROM).withDestination(destination)
            .withMessage(message);/*from  w w w. j a v a 2 s. c o  m*/

    try {
        System.out.println("Attempting to send an email through Amazon SES by using the AWS SDK for Java...");

        /*
         * The ProfileCredentialsProvider will return your [haow2]
         * credential profile by reading from the credentials file located at
         * (/Users/Dawn/.aws/credentials).
         *
         * TransferManager manages a pool of threads, so we create a
         * single instance and share it throughout our application.
         */
        AWSCredentials credentials = null;
        try {
            credentials = new ProfileCredentialsProvider("haow2").getCredentials();
        } catch (Exception e) {
            throw new AmazonClientException("Cannot load the credentials from the credential profiles file. "
                    + "Please make sure that your credentials file is at the correct "
                    + "location (/Users/Dawn/.aws/credentials), and is in valid format.", e);
        }

        // Instantiate an Amazon SES client, which will make the service call with the supplied AWS credentials.
        AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(credentials);

        // Choose the AWS region of the Amazon SES endpoint you want to connect to. Note that your production
        // access status, sending limits, and Amazon SES identity-related settings are specific to a given
        // AWS region, so be sure to select an AWS region in which you set up Amazon SES. Here, we are using
        // the US East (N. Virginia) region. Examples of other regions that Amazon SES supports are US_WEST_2
        // and EU_WEST_1. For a complete list, see http://docs.aws.amazon.com/ses/latest/DeveloperGuide/regions.html
        Region REGION = Region.getRegion(Regions.US_EAST_1);
        client.setRegion(REGION);

        // Send the email.
        client.sendEmail(request);
        System.out.println("Email sent!");

    } catch (Exception ex) {
        System.out.println("The email was not sent.");
        System.out.println("Error message: " + ex.getMessage());
    }
}

From source file:com.adeptj.modules.aws.ses.internal.AwsSesService.java

License:Apache License

/**
 * {@inheritDoc}//from  w  ww. j  ava  2s  .  c  o  m
 */
@Override
public EmailResponse sendEmail(EmailRequest emailRequest) {
    try {
        SendEmailResult result = this.asyncSES
                .sendEmail(new SendEmailRequest().withSource(this.emailConfig.from())
                        .withDestination(new Destination().withToAddresses(emailRequest.getRecipientToList())
                                .withCcAddresses(emailRequest.getRecipientCcList())
                                .withBccAddresses(emailRequest.getRecipientBccList()))
                        .withMessage(new Message()
                                .withSubject(new Content().withData(emailRequest.getSubject())).withBody(
                                        new Body().withHtml(new Content().withData(emailRequest.getBody())))));
        return new EmailResponse(result.getMessageId(), result.getSdkHttpMetadata().getHttpStatusCode(),
                result.getSdkHttpMetadata().getHttpHeaders());
    } catch (Exception ex) {
        LOGGER.error("Exception while sending email!!", ex);
        throw new AwsException(ex.getMessage(), ex);
    }
}

From source file:com.adeptj.modules.aws.ses.internal.AwsSesService.java

License:Apache License

/**
 * {@inheritDoc}/*from ww w . ja  v  a2  s .  c  o m*/
 */
@Override
public void sendEmailAsync(EmailRequest emailRequest) {
    try {
        // Shall we use the Future object returned by async call?
        this.asyncSES.sendEmailAsync(
                new SendEmailRequest().withSource(this.emailConfig.from())
                        .withDestination(new Destination().withToAddresses(emailRequest.getRecipientToList())
                                .withCcAddresses(emailRequest.getRecipientCcList())
                                .withBccAddresses(emailRequest.getRecipientBccList()))
                        .withMessage(
                                new Message().withSubject(new Content().withData(emailRequest.getSubject()))
                                        .withBody(new Body()
                                                .withHtml(new Content().withData(emailRequest.getBody())))),
                this.asyncHandler);
    } catch (Exception ex) {
        LOGGER.error("Exception while sending email asynchronously!!", ex);
    }
}

From source file:com.app.ses.AmazonSES.java

License:Open Source License

public void sendMail(String TO, String USUARIO2, String SUBJECT, String CONTENIDO, String FOLIO,
        String USERCREATE, String NOMBRE) {

    // Construct an object to contain the recipient address.
    Destination destination = new Destination().withToAddresses(new String[] { TO });

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

    Content htmlContent = new Content().withData(" <body bgcolor=\"#FFFFFF\">\n" + "    <!-- HEADER -->\n"
            + "        <table class=\"head-wrap\" bgcolor=\"red\">\n" + "            <tr>\n"
            + "                <td></td>\n" + "                <td class=\"header container\" >\n"
            + "                    <div class=\"content\">\n"
            + "                        <table bgcolor=\"red\">\n" + "                            <tr>\n"
            + "                                <td style=\"font-size: x-large; color:white;\">\n"
            + "                                    S G C o n\n" + "                                </td>\n"
            + "                                <td style=\"text-align: right; color:white; fon\">\n"
            + "                                    Notificaciones\n" + "                                </td>\n"
            + "                            </tr>\n" + "                        </table>\n"
            + "                    </div>\n" + "                </td>\n" + "                <td></td>\n"
            + "            </tr>\n" + "        </table><!-- /HEADER -->\n" + "        <!-- BODY -->\n"
            + "        <table class=\"body-wrap\">\n" + "            <tr>\n" + "                <td></td>\n"
            + "                <td class=\"container\" bgcolor=\"#FFFFFF\">\n"
            + "                    <div class=\"content\">\n" + "                        <table>\n"
            + "                            <tr>\n" + "                                <td>\n"
            + "                                    <h3>Hola, " + USUARIO2 + "</h3>\n"
            + "                                    <p class=\"callout\">\n"
            + "                                        " + CONTENIDO + "\n"
            + "                                    </p>\n" + "                                    <p>\n"
            + "                                        <table style=\"font-size: medium\">\n"
            + "                                            <tr>\n"
            + "                                                <td>Folio: " + FOLIO + "</td>\n"
            + "                                            </tr>\n"
            + "                                            <tr>\n"
            + "                                                <td>" + USERCREATE + "</td>\n"
            + "                                            </tr>\n"
            + "                                            <tr>\n"
            + "                                                <td>" + NOMBRE + "</td>\n"
            + "                                            </tr>\n"
            + "                                        </table>\n"
            + "                                    </p> <br/>\n"
            + "                                     <table>\n"
            + "                                         <tr>\n"
            + "                                             <td>\n"
            + "                                                 <p>\n"
            + "                                                     <a href=\"http://www.sgcon-infonavit.com\" class=\"soc-btn fb\">Ir a la aplicacin</a> \n"
            + "                                                 </p>\n"
            + "                                             </td>\n"
            + "                                         </tr>\n"
            + "                                     </table\n" + "                                </td>\n"
            + "                            </tr>\n" + "                        </table>\n"
            + "                    </div>\n" + "                </td>\n" + "                <td></td>\n"
            + "            </tr>\n" + "        </table>\n" + "    </body>");

    Body body = new Body().withHtml(htmlContent);

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

    // Assemble the email.
    SendEmailRequest request = new SendEmailRequest().withSource(FROM).withDestination(destination)
            .withMessage(message);//from   w  ww  . j  a  va2  s .  c o  m

    try {
        System.out.println("Attempting to send an email through Amazon SES by using the AWS SDK for Java...");

        /*
         * The ProfileCredentialsProvider will return your [default]
         * credential profile by reading from the credentials file located at
         * (~/.aws/credentials).
         *
         * TransferManager manages a pool of threads, so we create a
         * single instance and share it throughout our application.
         */
        /*AWSCredentials credentials = null;
         try {
         credentials = new ProfileCredentialsProvider().getCredentials();
         } catch (Exception e) {
         throw new AmazonClientException(
         "Cannot load the credentials from the credential profiles file. "
         + "Please make sure that your credentials file is at the correct "
         + "location (~/.aws/credentials), and is in valid format.",
         e);
         }*/
        AWSCredentials awsCreds = new BasicAWSCredentials("AKIAJFO4NNHIPNTB4ZCQ",
                "VjYeQ9+xj3HAcLBSxxxbHTo6jy2ft0wF6tgWZXmA");
        // Instantiate an Amazon SES client, which will make the service call with the supplied AWS credentials.
        //AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(credentials);
        AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(awsCreds);

        // Choose the AWS region of the Amazon SES endpoint you want to connect to. Note that your production
        // access status, sending limits, and Amazon SES identity-related settings are specific to a given
        // AWS region, so be sure to select an AWS region in which you set up Amazon SES. Here, we are using
        // the US East (N. Virginia) region. Examples of other regions that Amazon SES supports are US_WEST_2
        // and EU_WEST_1. For a complete list, see http://docs.aws.amazon.com/ses/latest/DeveloperGuide/regions.html
        Region REGION = Region.getRegion(Regions.US_WEST_2);
        client.setRegion(REGION);

        // Send the email.
        client.sendEmail(request);
        System.out.println("Email sent!");

    } catch (Exception ex) {
        System.out.println("The email was not sent.");
        System.out.println("Error message: " + ex.getMessage());
    }
}

From source file:com.app.ses.AmazonSES.java

License:Open Source License

public void sendMailDos(String TO, String USUARIO2, String SUBJECT, String CONTENIDO, String LISTA) {

    System.out.println("Si imprime la llamada del la clase  djscnlskdncfksdlncfksdcldsncewldn");

    //operaciones con el json       
    // Construct an object to contain the recipient address.
    Destination destination = new Destination().withToAddresses(new String[] { TO });

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

    Content htmlContent = new Content().withData(" <body bgcolor=\"#FFFFFF\">\n" + "    <!-- HEADER -->\n"
            + "        <table class=\"head-wrap\" bgcolor=\"red\">\n" + "            <tr>\n"
            + "                <td></td>\n" + "                <td class=\"header container\" >\n"
            + "                    <div class=\"content\">\n"
            + "                        <table bgcolor=\"red\">\n" + "                            <tr>\n"
            + "                                <td style=\"font-size: x-large; color:white;\">\n"
            + "                                    S G C o n\n" + "                                </td>\n"
            + "                                <td style=\"text-align: right; color:white; fon\">\n"
            + "                                    Notificaciones\n" + "                                </td>\n"
            + "                            </tr>\n" + "                        </table>\n"
            + "                    </div>\n" + "                </td>\n" + "                <td></td>\n"
            + "            </tr>\n" + "        </table><!-- /HEADER -->\n" + "        <!-- BODY -->\n"
            + "        <table class=\"body-wrap\">\n" + "            <tr>\n" + "                <td></td>\n"
            + "                <td class=\"container\" bgcolor=\"#FFFFFF\">\n"
            + "                    <div class=\"content\">\n" + "                        <table>\n"
            + "                            <tr>\n" + "                                <td>\n"
            + "                                    <h3>Hola, " + USUARIO2 + "</h3>\n"
            + "                                    <p class=\"callout\">\n"
            + "                                        " + CONTENIDO + "\n"
            + "                                    </p>\n" + "                                    <p>\n"
            + "                                        <table style=\"font-size: medium\">\n"
            + "                                            <tr>\n"
            + "                                                <td>Folio: " + LISTA + "</td>\n"
            + "                                            </tr>\n"
            + "                                        </table>\n"
            + "                                    </p> <br/>\n"
            + "                                     <table>\n"
            + "                                         <tr>\n"
            + "                                             <td>\n"
            + "                                                 <p>\n"
            + "                                                     <a href=\"http://www.sgcon-infonavit.com\" class=\"soc-btn fb\">Ir a la aplicacin</a> \n"
            + "                                                 </p>\n"
            + "                                             </td>\n"
            + "                                         </tr>\n"
            + "                                     </table\n" + "                                </td>\n"
            + "                            </tr>\n" + "                        </table>\n"
            + "                    </div>\n" + "                </td>\n" + "                <td></td>\n"
            + "            </tr>\n" + "        </table>\n" + "    </body>");

    Body body = new Body().withHtml(htmlContent);

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

    // Assemble the email.
    SendEmailRequest request = new SendEmailRequest().withSource(FROM).withDestination(destination)
            .withMessage(message);/*ww  w  . j a  v a2  s.  c  om*/

    try {
        System.out.println("Attempting to send an email through Amazon SES by using the AWS SDK for Java...");

        /*
         * The ProfileCredentialsProvider will return your [default]
         * credential profile by reading from the credentials file located at
         * (~/.aws/credentials).
         *
         * TransferManager manages a pool of threads, so we create a
         * single instance and share it throughout our application.
         */
        /*AWSCredentials credentials = null;
         try {
         credentials = new ProfileCredentialsProvider().getCredentials();
         } catch (Exception e) {
         throw new AmazonClientException(
         "Cannot load the credentials from the credential profiles file. "
         + "Please make sure that your credentials file is at the correct "
         + "location (~/.aws/credentials), and is in valid format.",
         e);
         }*/
        AWSCredentials awsCreds = new BasicAWSCredentials("AKIAJFO4NNHIPNTB4ZCQ",
                "VjYeQ9+xj3HAcLBSxxxbHTo6jy2ft0wF6tgWZXmA");
        // Instantiate an Amazon SES client, which will make the service call with the supplied AWS credentials.
        //AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(credentials);
        AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(awsCreds);

        // Choose the AWS region of the Amazon SES endpoint you want to connect to. Note that your production
        // access status, sending limits, and Amazon SES identity-related settings are specific to a given
        // AWS region, so be sure to select an AWS region in which you set up Amazon SES. Here, we are using
        // the US East (N. Virginia) region. Examples of other regions that Amazon SES supports are US_WEST_2
        // and EU_WEST_1. For a complete list, see http://docs.aws.amazon.com/ses/latest/DeveloperGuide/regions.html
        Region REGION = Region.getRegion(Regions.US_WEST_2);
        client.setRegion(REGION);

        // Send the email.
        client.sendEmail(request);
        System.out.println("Email sent!");

    } catch (Exception ex) {
        System.out.println("The email was not sent.");
        System.out.println("Error message: " + ex.getMessage());
    }
}

From source file:com.devnexus.ting.core.service.integration.AmazonSesSender.java

License:Apache License

public void sendUsingSendgrid(GenericEmail email) {

    final Destination destination = new Destination(email.getTo());
    destination.setCcAddresses(email.getCc());

    final Content subject = new Content(email.getSubject());
    final Content htmlContent = new Content().withData(email.getHtml());
    final Content textContent = new Content().withData(email.getText());

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

    final Message message = new Message().withSubject(subject).withBody(body);

    final SendEmailRequest request = new SendEmailRequest().withSource(email.getFrom())
            .withDestination(destination).withMessage(message);

    final Region REGION = Region.getRegion(Regions.US_EAST_1);
    client.setRegion(REGION);// www  . jav  a  2 s .co m

    // Send the email.
    client.sendEmail(request);
    LOGGER.info("Email sent to {}", email.getTo());

}

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);/*from  ww  w.  j a  va  2s.c o  m*/

        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);

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

From source file:com.espressologic.aws.sqs.AmazonEmailService.java

License:Open Source License

/**
 * build the email message//from  ww w .  ja va2s .  co  m
 *
 * @param messageTo
 * @param messageFrom
 * @param msgSubject
 * @param msgBody
 * @return
 */
public static SendEmailRequest createEmailRequestInternal(String messageTo, String messageFrom,
        String msgSubject, String msgBody) {
    Destination destination = new Destination().withToAddresses(new String[] { messageTo });

    // Create the subject and body of the message.
    Content subject = new Content().withData(msgSubject);
    Content textBody = new Content().withData(msgBody);
    Body body = new Body().withText(textBody);

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

    // Assemble the email.
    return new SendEmailRequest().withSource(messageFrom).withDestination(destination).withMessage(message);
}

From source file:com.hiveTown.util.AmazonSESUtil.java

License:Open Source License

public boolean sendEmail(String[] toEmail, String strBody, String strSubject, String fromAddress,
        String replyToAddress) throws IOException {

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

    // Create the subject and body of the message.
    Content subject = new Content().withData(strSubject);
    Content textBody = new Content().withData(strBody);
    Body body = new Body().withHtml(textBody);

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

    // Assemble the email.
    SendEmailRequest request = new SendEmailRequest().withSource(fromAddress).withDestination(destination)
            .withMessage(message).withReplyToAddresses(replyToAddress);
    boolean isEmailSent = false;
    try {/*  w ww  .  j  a v a  2  s. co  m*/
        // Send the email.
        SendEmailResult r = this.getClient().sendEmail(request);
        LOGGER.info(r.toString());
        isEmailSent = true;

    } catch (Exception ex) {
        LOGGER.error(ex.toString());
    }
    return isEmailSent;
}

From source file:com.irurueta.server.commons.email.AWSTextEmailMessage.java

License:Apache License

/**
 * Builds email content to be sent using an email sender.
 * @param message instance where content must be set.
 * @throws EmailException if setting mail content fails.
 *///from  w ww. j a v a 2  s  . c o m
@Override
protected void buildContent(Message message) throws EmailException {
    Destination destination = new Destination(getTo());
    if (getBCC() != null && !getBCC().isEmpty()) {
        destination.setBccAddresses(getBCC());
    }
    if (getCC() != null && !getCC().isEmpty()) {
        destination.setCcAddresses(getCC());
    }

    if (getSubject() != null) {
        Content subject = new Content(getSubject());
        //set utf-8 enconding to support all languages
        subject.setCharset("UTF-8");
        message.setSubject(subject);
    }

    if (getText() != null) {
        Body body = new Body();
        Content content = new Content(getText());
        //set utf-8 enconding to support all languages            
        content.setCharset("UTF-8");

        body.setText(content);
        message.setBody(body);
    }
}