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

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

Introduction

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

Prototype

AmazonSimpleEmailServiceAsyncClient(AwsAsyncClientParams asyncClientParams) 

Source Link

Document

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

Usage

From source file:com.aipo.aws.ses.SES.java

License:Open Source License

public static AmazonSimpleEmailServiceAsync getAsyncClient() {
    AWSContext awsContext = AWSContext.get();
    if (awsContext == null) {
        throw new IllegalStateException("AWSContext is not initialized.");
    }/*from  w w w.  j  a v a2s.c  o m*/
    AmazonSimpleEmailServiceAsync client = new AmazonSimpleEmailServiceAsyncClient(
            awsContext.getAwsCredentials());
    String endpoint = awsContext.getSesEndpoint();
    if (endpoint != null && endpoint != "") {
        client.setEndpoint(endpoint);
    }
    return client;
}

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  .  j  a  v a2s . co  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:net.encomendaz.services.util.Mailer.java

License:Open Source License

public static AmazonSimpleEmailServiceAsync client() {
    String accessKey = Configuration.awsAccessKey();
    String secretKey = Configuration.awsSecretKey();

    AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
    return new AmazonSimpleEmailServiceAsyncClient(credentials);
}

From source file:org.onebusaway.admin.service.impl.EmailServiceImpl.java

License:Apache License

@PostConstruct
@Override// ww  w  .  j  a  v  a2s  . c  o m
public void setup() {
    try {
        String mailSMTPServer = "";
        String mailSMTPServerPort = "";
        // Try getting smtp host and port values from configurationService.
        try {
            mailSMTPServer = configurationService.getConfigurationValueAsString("admin.smtpHost",
                    SMTP_HOST_NOT_FOUND);
            mailSMTPServerPort = configurationService.getConfigurationValueAsString("admin.smtpPort", "25");
        } catch (RemoteConnectFailureException e) {
            _log.error("Setting smtp host to value : '" + SMTP_HOST_NOT_FOUND
                    + "' due to failure to connect to TDM");
            mailSMTPServer = SMTP_HOST_NOT_FOUND;
            e.printStackTrace();
        }

        // If smtp host name was not found, assume this should use AWS
        _properties = new Properties();
        boolean useSMTP = mailSMTPServer.equals(SMTP_HOST_NOT_FOUND) ? false : true;
        if (useSMTP) { // Configure for SMTP
            _properties.setProperty("mail.transport.protocol", "smtp");
            _properties.setProperty("mail.smtp.starttls.enable", "false");
            _properties.setProperty("mail.smtp.host", mailSMTPServer);
            _properties.setProperty("mail.smtp.auth", "false");
            _properties.setProperty("mail.debug", "false");
            _properties.setProperty("mail.smtp.port", mailSMTPServerPort);
        } else { // Configure for AWS
            // AWS specifics
            _credentials = new BasicAWSCredentials(_username, _password);
            _eClient = new AmazonSimpleEmailServiceAsyncClient(_credentials);
            // Java specifics
            _properties.setProperty("mail.transport.protocol", "aws");
            _properties.setProperty("mail.aws.user", _credentials.getAWSAccessKeyId());
            _properties.setProperty("mail.aws.password", _credentials.getAWSSecretKey());
        }

        _session = Session.getInstance(_properties);
        Session session = Session.getDefaultInstance(_properties);
        session.setDebug(false);
        _transport = useSMTP ? _session.getTransport("smtp") : new AWSJavaMailTransport(_session, null);
    } catch (Exception ioe) {
        // log this heavily, but don't let it prevent context startup
        _log.error("EmailServiceImpl setup failed, likely due to missing or invalid credentials.");
        _log.error(ioe.toString());
    }
}