Example usage for com.amazonaws.services.simpleemail AmazonSimpleEmailServiceClient setRegion

List of usage examples for com.amazonaws.services.simpleemail AmazonSimpleEmailServiceClient setRegion

Introduction

In this page you can find the example usage for com.amazonaws.services.simpleemail AmazonSimpleEmailServiceClient setRegion.

Prototype

@Deprecated
public void setRegion(Region region) throws IllegalArgumentException 

Source Link

Document

An alternative to AmazonWebServiceClient#setEndpoint(String) , sets the regional endpoint for this client's service calls.

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);// w w w . j  a va  2  s .com

    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.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 w  w  . j a  va 2 s.com*/

    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);/*from   w  ww  .  ja va  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 [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.espressologic.aws.sqs.AmazonEmailService.java

License:Open Source License

/**
 * send email using credentials and region
 *
 * @param request/*from   ww w .ja  va 2 s.c o  m*/
 * @throws Exception
 */
public static void sendEmalRequest(SendEmailRequest request) throws Exception {
    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.
         */
        createAWSCredentials();

        // 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(getMyRegion());
        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());
        throw ex;
    }
}

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

License:Open Source License

private AmazonSimpleEmailServiceClient getClient() {

    BasicAWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);

    // Instantiate an Amazon SES client, which will make the service call with the supplied AWS credentials.
    AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(credentials);
    Region REGION = Region.getRegion(Regions.US_WEST_2);
    client.setRegion(REGION);
    return client;
}

From source file:com.prd.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);// w  ww.j  a  v a 2s . com

    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
         * (/Users/prabhjitsingh/.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("default").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/prabhjitsingh/.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.solomon.aws.service.AwsMailServ.java

public void sendMail() {
    Destination destination = new Destination().withToAddresses(new String[] { to });
    Content subject = new Content().withData(topic);
    Content textBody = new Content().withData(body);
    Body mailBody = new Body().withText(textBody);

    Message message = new Message().withSubject(subject).withBody(mailBody);
    SendEmailRequest request = new SendEmailRequest().withSource(from).withDestination(destination)
            .withMessage(message);/*from  w w w .ja v a2s. co  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 [New US East (Virginia) Profile]
         * credential profile by reading from the credentials file located at
         * (/Users/zhao0677/.aws/credentials).
         *
         * TransferManager manages a pool of threads, so we create a
         * single instance and share it throughout our application.
         */

        try {
            AWSCredentials credentials = AwsUtil.getAwsCredentials();
            AmazonSimpleEmailServiceClient client = AwsUtil.getAwsEmailServClient(credentials);
            Region REGION = Region.getRegion(AwsUtil.DEVELOPER_REGION);
            client.setRegion(REGION);

            // Send the email.
            client.sendEmail(request);
            System.out.println("Email sent!");
        } 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, and is in valid format.", e);
        }

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

From source file:es.logongas.fpempresa.service.mail.impl.MailServiceImplAWS.java

License:Open Source License

@Override
public void send(Mail mail) {
    try {/*from w w w. ja  v a  2s  . c  o m*/
        Session session = Session.getDefaultInstance(new Properties());

        Message message = JavaMailHelper.getMessage(mail, session);

        //Aqu es el proceso de envio
        AWSCredentials credentials = new BasicAWSCredentials(Config.getSetting("aws.accessKey"),
                Config.getSetting("aws.secretKey"));
        AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceAsyncClient(credentials);
        Region REGION = Region.getRegion(Regions.EU_WEST_1);
        client.setRegion(REGION);
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        message.writeTo(outputStream);
        RawMessage rawMessage = new RawMessage(ByteBuffer.wrap(outputStream.toByteArray()));
        SendRawEmailRequest rawEmailRequest = new SendRawEmailRequest(rawMessage);
        client.sendRawEmail(rawEmailRequest);
    } catch (IllegalArgumentException | IOException | MessagingException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:io.kodokojo.service.aws.SesEmailSender.java

License:Open Source License

@Override
public void send(List<String> to, List<String> cc, List<String> ci, String object, String content,
        boolean htmlContent) {
    if (CollectionUtils.isEmpty(to)) {
        throw new IllegalArgumentException("to must be defined.");
    }/*  ww  w .  ja v a  2s.c o m*/
    if (isBlank(content)) {
        throw new IllegalArgumentException("content must be defined.");
    }
    Destination destination = new Destination().withToAddresses(to).withBccAddresses(ci).withCcAddresses(cc);
    Content subject = new Content().withData(object);
    Content bodyContent = new Content().withData(content);
    Body body;
    if (htmlContent) {
        body = new Body().withHtml(bodyContent);
    } else {
        body = new Body().withText(bodyContent);
    }
    Message message = new Message().withSubject(subject).withBody(body);
    SendEmailRequest request = new SendEmailRequest().withSource(from).withDestination(destination)
            .withMessage(message);
    try {
        AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient();
        client.setRegion(region);
        client.sendEmail(request);
    } catch (Exception e) {
        LOGGER.error("Unable to send email to {} with subject '{}'", StringUtils.join(to, ","), subject, e);
    }
}

From source file:jp.co.hde.mail.ses.AmazonSESSample.java

License:Apache 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(TEXT_BODY);
    Content htmlBody = new Content().withData(HTML_BODY);
    Body body = new Body().withHtml(htmlBody);

    // Create a message with the specified subject and body.
    Message message = new Message().withSubject(subject).withBody(body);
    com.amazonaws.services.simpleemail.model.

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

    try {//from www . j  a  v  a  2 s  .  c  om
        System.out.println("Attempting to send an email through Amazon SES by using the AWS SDK for Java...");

        // Instantiate an Amazon SES client, which will make the service call. The service call requires your AWS credentials. 
        // Because we're not providing an argument when instantiating the client, the SDK will attempt to find your AWS credentials 
        // using the default credential provider chain. The first place the chain looks for the credentials is in environment variables 
        // AWS_ACCESS_KEY_ID and AWS_SECRET_KEY. 
        // For more information, see http://docs.aws.amazon.com/AWSSdkDocsJava/latest/DeveloperGuide/credentials.html
        AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient();

        // Choose the AWS region of the Amazon SES endpoint you want to connect to. Note that your sandbox 
        // 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  region. Examples of other regions that Amazon SES supports are US_EAST_1 
        // 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());
    }
}