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:org.openchain.certification.utility.EmailUtility.java

License:Apache License

private static AmazonSimpleEmailServiceClient getEmailClient(ServletConfig config) throws EmailUtilException {
    String regionName = config.getServletContext().getInitParameter("email_ses_region");
    if (regionName == null || regionName.isEmpty()) {
        logger.error("Missing email_ses_region parameter in the web.xml file");
        throw (new EmailUtilException(
                "The region name for the email facility has not been set.  Pleaese contact the OpenChain team with this error."));
    }/*  w w  w  .j a v  a 2  s . c  om*/
    String secretKey = null;
    String accessKey = System.getenv(ACCESS_KEY_VAR);
    if (accessKey == null) {
        accessKey = System.getProperty(ACCESS_KEY_VAR);
        if (accessKey != null) {
            secretKey = System.getProperty(SECRET_KEY_VAR);
        }
    } else {
        secretKey = System.getenv(SECRET_KEY_VAR);
    }
    AmazonSimpleEmailServiceClient retval = null;
    if (accessKey != null) {
        AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
        retval = new AmazonSimpleEmailServiceClient(credentials);
    } else {
        retval = new AmazonSimpleEmailServiceClient();
    }
    Region region = Region.getRegion(Regions.fromName(regionName));
    retval.setRegion(region);
    return retval;
}

From source file:org.springframework.cloud.aws.autoconfigure.mail.MailSenderAutoConfiguration.java

License:Apache License

@Bean
@ConditionalOnMissingAmazonClient(AmazonSimpleEmailService.class)
public AmazonSimpleEmailService amazonSimpleEmailService(AWSCredentialsProvider credentialsProvider) {
    AmazonSimpleEmailServiceClient serviceClient = new AmazonSimpleEmailServiceClient(credentialsProvider);
    if (this.regionProvider != null) {
        serviceClient.setRegion(this.regionProvider.getRegion());
    }/*from   ww w  . j  a  v  a2  s .c o m*/
    return serviceClient;
}

From source file:uk.co.jassoft.email.EmailSenderService.java

public void send(String recipientAddress, String subject, Map emailContent) throws EmailSendException {
    try {/*from   w ww . j  a  v  a 2  s  .c  om*/
        if (System.getenv("API_SEND_EMAILS").equals("false")) {
            LOG.info("API_SEND_EMAILS is set to [{}]", System.getenv("API_SEND_EMAILS"));
            return;
        }

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

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

        Body body = new Body();

        if (template != null)
            body = body.withText(new Content().withData(VelocityEngineUtils
                    .mergeTemplateIntoString(velocityEngine, template, "UTF-8", emailContent)));

        if (htmlTemplate != null)
            body = body.withHtml(new Content().withData(VelocityEngineUtils
                    .mergeTemplateIntoString(velocityEngine, htmlTemplate, "UTF-8", emailContent)));

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

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

        AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(
                new EnvironmentVariableCredentialsProvider());
        Region REGION = Region.getRegion(Regions.EU_WEST_1);
        client.setRegion(REGION);

        // Send the email.
        client.sendEmail(request);
    } catch (Exception exception) {
        throw new EmailSendException(exception.getMessage(), exception);
    }
}