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

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

Introduction

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

Prototype

AmazonSimpleEmailServiceClient(AwsSyncClientParams clientParams) 

Source Link

Document

Constructs a new client to invoke service methods on Amazon SES using the specified parameters.

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."));
    }//from  www .  j a  v  a  2s .c  o  m
    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   w ww  . j  a v  a2 s.  com*/
    return serviceClient;
}

From source file:org.springframework.integration.aws.ses.core.AmazonSESMailSenderImpl.java

License:Apache License

public AmazonSESMailSenderImpl(AmazonWSCredentials credentials) {
    if (credentials == null)
        throw new AmazonWSOperationException(null,
                "Credentials cannot be null, provide a non null valid set of credentials");
    this.credentials = credentials;

    emailService = new AmazonSimpleEmailServiceClient(
            new BasicAWSCredentials(credentials.getAccessKey(), credentials.getSecretKey()));
}

From source file:spikes.email.AmazonSimpleEmailServiceSpike.java

License:Open Source License

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

    PropertiesCredentials credentials = new PropertiesCredentials(
            AmazonSimpleEmailServiceSpike.class.getResourceAsStream("AwsCredentials.properties"));

    AmazonSimpleEmailService service = new AmazonSimpleEmailServiceClient(credentials);

    verifyAddressIfNecessary(service, FROM);

    Destination destination = new Destination(Arrays.asList(TO));
    Content subject = new Content(SUBJECT);
    Body body = new Body().withHtml(new Content(BODY));
    Message message = new Message(subject, body);
    service.sendEmail(new SendEmailRequest(from(), destination, message));

    System.exit(0);//from   w  w w. j  a  v  a  2  s . c  o m

}

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

public void send(String recipientAddress, String subject, Map emailContent) throws EmailSendException {
    try {//w w w. j  a va 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);
    }
}