Java 类com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient 实例源码

项目:oneops    文件:EmailService.java   
/**
 * Inits the.
 */
public void init() {
    if (this.awsAccessKey == null) {
        this.awsAccessKey = System.getenv("AWS_ACCESS_KEY");
        if (this.awsAccessKey == null) {
            this.awsAccessKey = System.getProperty("com.oneops.aws.accesskey");
        }
    }

    if (this.awsSecretKey == null) {
        this.awsSecretKey = System.getenv("AWS_SECRET_KEY");
        if (this.awsSecretKey == null) {
            this.awsSecretKey = System.getProperty("com.oneops.aws.secretkey");
        }
    }

    emailClient = new AmazonSimpleEmailServiceClient(
            new BasicAWSCredentials(awsAccessKey, awsSecretKey));
}
项目:kodokojo    文件:SesEmailSender.java   
private void sendSimpleMail(List<String> to, List<String> cc, List<String> ci, String object, String content, boolean htmlContent) {

        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);
        }
    }
项目:Online-Self-Certification-Web-App    文件:EmailUtility.java   
public static void emailVerification(String name, String email, UUID uuid, 
        String username, String responseServletUrl, ServletConfig config) throws EmailUtilException {
    String fromEmail = config.getServletContext().getInitParameter("return_email");
    if (fromEmail == null || fromEmail.isEmpty()) {
        logger.error("Missing return_email parameter in the web.xml file");
        throw(new EmailUtilException("The from email for the email facility has not been set.  Pleaese contact the OpenChain team with this error."));
    }
    String link = responseServletUrl + "?request=register&username=" + username + "&uuid=" + uuid.toString();
    StringBuilder msg = new StringBuilder("<div>Welcome ");
    msg.append(name);
    msg.append(" to the OpenChain Certification website.<br /> <br />To complete your registration, click on the following or copy/paste into your web browser <a href=\"");
    msg.append(link);
    msg.append("\">");
    msg.append(link);
    msg.append("</a><br/><br/>Thanks,<br/>The OpenChain team</div>");
    Destination destination = new Destination().withToAddresses(new String[]{email});
    Content subject = new Content().withData("OpenChain Registration [do not reply]");
    Content bodyData = new Content().withData(msg.toString());
    Body body = new Body();
    body.setHtml(bodyData);
    Message message = new Message().withSubject(subject).withBody(body);
    SendEmailRequest request = new SendEmailRequest().withSource(fromEmail).withDestination(destination).withMessage(message);
    try {
        AmazonSimpleEmailServiceClient client = getEmailClient(config);
        client.sendEmail(request);
        logger.info("Invitation email sent to "+email);
    } catch (Exception ex) {
        logger.error("Email send failed",ex);
        throw(new EmailUtilException("Exception occured during the emailing of the invitation",ex));
    }
}
项目:Online-Self-Certification-Web-App    文件:EmailUtility.java   
@SuppressWarnings("unused")
private static void logMailInfo(AmazonSimpleEmailServiceClient client, ServletConfig config) {
    logger.info("Email Service Name: "+client.getServiceName());
    List<String> identities = client.listIdentities().getIdentities();
    for (String identity:identities) {
        logger.info("Email identity: "+identity);
    }
    List<String> verifiedEmails = client.listVerifiedEmailAddresses().getVerifiedEmailAddresses();
    for (String email:verifiedEmails) {
        logger.info("Email verified email address: "+email);
    }
    GetSendQuotaResult sendQuota = client.getSendQuota();
    logger.info("Max 24 hour send="+sendQuota.getMax24HourSend()+", Max Send Rate="+
    sendQuota.getMaxSendRate() + ", Sent last 24 hours="+sendQuota.getSentLast24Hours());
}
项目:Online-Self-Certification-Web-App    文件:EmailUtility.java   
public static void emailUser(String toEmail, String subjectText, String msg, ServletConfig config) throws EmailUtilException {
    String fromEmail = config.getServletContext().getInitParameter("return_email");
    if (fromEmail == null || fromEmail.isEmpty()) {
        logger.error("Missing return_email parameter in the web.xml file");
        throw(new EmailUtilException("The from email for the email facility has not been set.  Pleaese contact the OpenChain team with this error."));
    }
    if (toEmail == null || toEmail.isEmpty()) {
        logger.error("Missing notification_email parameter in the web.xml file");
        throw(new EmailUtilException("The to email for the email facility has not been set.  Pleaese contact the OpenChain team with this error."));
    }

    Destination destination = new Destination().withToAddresses(new String[]{toEmail});
    Content subject = new Content().withData(subjectText);
    Content bodyData = new Content().withData(msg.toString());
    Body body = new Body();
    body.setHtml(bodyData);
    Message message = new Message().withSubject(subject).withBody(body);
    SendEmailRequest request = new SendEmailRequest().withSource(fromEmail).withDestination(destination).withMessage(message);
    try {
        AmazonSimpleEmailServiceClient client = getEmailClient(config);
        client.sendEmail(request);
        logger.info("User email sent to "+toEmail+": "+msg);
    } catch (Exception ex) {
        logger.error("Email send failed",ex);
        throw(new EmailUtilException("Exception occured during the emailing of a user email",ex));
    }
}
项目:Online-Self-Certification-Web-App    文件:EmailUtility.java   
public static void emailAdmin(String subjectText, String msg, ServletConfig config) throws EmailUtilException {
    String fromEmail = config.getServletContext().getInitParameter("return_email");
    if (fromEmail == null || fromEmail.isEmpty()) {
        logger.error("Missing return_email parameter in the web.xml file");
        throw(new EmailUtilException("The from email for the email facility has not been set.  Pleaese contact the OpenChain team with this error."));
    }
    String toEmail = config.getServletContext().getInitParameter("notification_email");
    if (toEmail == null || toEmail.isEmpty()) {
        logger.error("Missing notification_email parameter in the web.xml file");
        throw(new EmailUtilException("The to email for the email facility has not been set.  Pleaese contact the OpenChain team with this error."));
    }

    Destination destination = new Destination().withToAddresses(new String[]{toEmail});
    Content subject = new Content().withData(subjectText);
    Content bodyData = new Content().withData(msg.toString());
    Body body = new Body();
    body.setHtml(bodyData);
    Message message = new Message().withSubject(subject).withBody(body);
    SendEmailRequest request = new SendEmailRequest().withSource(fromEmail).withDestination(destination).withMessage(message);
    try {
        AmazonSimpleEmailServiceClient client = getEmailClient(config);
        client.sendEmail(request);
        logger.info("Admin email sent to "+toEmail+": "+msg);
    } catch (Exception ex) {
        logger.error("Email send failed",ex);
        throw(new EmailUtilException("Exception occured during the emailing of the submission notification",ex));
    }
}
项目:Online-Self-Certification-Web-App    文件:EmailUtility.java   
/**
 * Email to notify a user that their profiles was updated
 * @param username
 * @param email
 * @param config
 * @throws EmailUtilException
 */
public static void emailProfileUpdate(String username, String email,
        ServletConfig config) throws EmailUtilException {
    String fromEmail = config.getServletContext().getInitParameter("return_email");
    if (fromEmail == null || fromEmail.isEmpty()) {
        logger.error("Missing return_email parameter in the web.xml file");
        throw(new EmailUtilException("The from email for the email facility has not been set.  Pleaese contact the OpenChain team with this error."));
    }
    StringBuilder msg = new StringBuilder("<div>The profile for username ");

    msg.append(username);
    msg.append(" has been updated.  If you this update has been made in error, please contact the OpenChain certification team.");
    Destination destination = new Destination().withToAddresses(new String[]{email});
    Content subject = new Content().withData("OpenChain Certification profile updated [do not reply]");
    Content bodyData = new Content().withData(msg.toString());
    Body body = new Body();
    body.setHtml(bodyData);
    Message message = new Message().withSubject(subject).withBody(body);
    SendEmailRequest request = new SendEmailRequest().withSource(fromEmail).withDestination(destination).withMessage(message);
    try {
        AmazonSimpleEmailServiceClient client = getEmailClient(config);
        client.sendEmail(request);
        logger.info("Notification email sent for "+email);
    } catch (Exception ex) {
        logger.error("Email send failed",ex);
        throw(new EmailUtilException("Exception occured during the emailing of the submission notification",ex));
    }
}
项目:Online-Self-Certification-Web-App    文件:EmailUtility.java   
public static void emailPasswordReset(String name, String email, UUID uuid,
        String username, String responseServletUrl, ServletConfig config) throws EmailUtilException {
    String fromEmail = config.getServletContext().getInitParameter("return_email");
    if (fromEmail == null || fromEmail.isEmpty()) {
        logger.error("Missing return_email parameter in the web.xml file");
        throw(new EmailUtilException("The from email for the email facility has not been set.  Pleaese contact the OpenChain team with this error."));
    }
    String link = responseServletUrl + "?request=pwreset&username=" + username + "&uuid=" + uuid.toString();
    StringBuilder msg = new StringBuilder("<div>To reset the your password, click on the following or copy/paste into your web browser <a href=\"");
    msg.append(link);
    msg.append("\">");
    msg.append(link);
    msg.append("</a><br/><br/><br/>The OpenChain team</div>");
    Destination destination = new Destination().withToAddresses(new String[]{email});
    Content subject = new Content().withData("OpenChain Password Reset [do not reply]");
    Content bodyData = new Content().withData(msg.toString());
    Body body = new Body();
    body.setHtml(bodyData);
    Message message = new Message().withSubject(subject).withBody(body);
    SendEmailRequest request = new SendEmailRequest().withSource(fromEmail).withDestination(destination).withMessage(message);
    try {
        AmazonSimpleEmailServiceClient client = getEmailClient(config);
        client.sendEmail(request);
        logger.info("Reset password email sent to "+email);
    } catch (Exception ex) {
        logger.error("Email send failed",ex);
        throw(new EmailUtilException("Exception occured during the emailing of the password reset",ex));
    }
}
项目:ExerciseMe    文件:AmazonClientManager.java   
private void initClients() {
    AWSCredentials credentials = AmazonSharedPreferencesWrapper
            .getCredentialsFromSharedPreferences(this.sharedPreferences);

    Region region = Region.getRegion(Regions.US_EAST_1);

    sesClient = new AmazonSimpleEmailServiceClient(credentials);
    sesClient.setRegion(region);
}
项目:glass    文件:EmailWebServiceTask.java   
public EmailWebServiceTask( Context context ) {
    String accessKey = context.getString(R.string.aws_access_key);
    String secretKey = context.getString(R.string.aws_secret_key);
    fromVerifiedAddress = context.getString(R.string.aws_verified_address);
    toAddress = getAccountEmail( context );
    AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
    sesClient = new AmazonSimpleEmailServiceClient( credentials );
}
项目:spring-cloud-aws    文件:SimpleEmailServiceBeanDefinitionParserTest.java   
@Test
public void parse_MailSenderWithMinimalConfiguration_createMailSenderWithJavaMail() throws Exception {
    //Arrange
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());

    //Act
    AmazonSimpleEmailServiceClient emailService = context.getBean(getBeanName(AmazonSimpleEmailServiceClient.class.getName()), AmazonSimpleEmailServiceClient.class);

    MailSender mailSender = context.getBean(MailSender.class);

    //Assert
    assertEquals("https://email.us-west-2.amazonaws.com", getEndpointUrlFromWebserviceClient(emailService));

    assertTrue(mailSender instanceof JavaMailSender);
}
项目:spring-cloud-aws    文件:SimpleEmailServiceBeanDefinitionParserTest.java   
@Test
public void parse_MailSenderWithRegionConfiguration_createMailSenderWithJavaMailAndRegion() throws Exception {
    //Arrange
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-region.xml", getClass());

    //Act
    AmazonSimpleEmailServiceClient emailService = context.getBean(getBeanName(AmazonSimpleEmailServiceClient.class.getName()), AmazonSimpleEmailServiceClient.class);

    MailSender mailSender = context.getBean(MailSender.class);

    //Assert
    assertEquals("https://email.eu-west-1.amazonaws.com", getEndpointUrlFromWebserviceClient(emailService));

    assertTrue(mailSender instanceof JavaMailSender);
}
项目:spring-cloud-aws    文件:SimpleEmailServiceBeanDefinitionParserTest.java   
@Test
public void parse_MailSenderWithRegionProviderConfiguration_createMailSenderWithJavaMailAndRegionFromRegionProvider() throws Exception {
    //Arrange
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-regionProvider.xml", getClass());

    //Act
    AmazonSimpleEmailServiceClient emailService = context.getBean(getBeanName(AmazonSimpleEmailServiceClient.class.getName()), AmazonSimpleEmailServiceClient.class);

    MailSender mailSender = context.getBean(MailSender.class);

    //Assert
    assertEquals("https://email.ap-southeast-2.amazonaws.com", getEndpointUrlFromWebserviceClient(emailService));

    assertTrue(mailSender instanceof JavaMailSender);
}
项目:spring-cloud-aws    文件:SimpleEmailServiceBeanDefinitionParserTest.java   
@Test
public void parse_MailSenderWithCustomSesClient_createMailSenderWithCustomSesClient() throws Exception {
    //Arrange
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-ses-client.xml", getClass());

    //Act
    AmazonSimpleEmailServiceClient emailService = context.getBean("emailServiceClient", AmazonSimpleEmailServiceClient.class);

    MailSender mailSender = context.getBean(MailSender.class);

    //Assert
    assertSame(emailService, ReflectionTestUtils.getField(mailSender, "emailService"));
}
项目:wildfly-camel    文件:SESIntegrationTest.java   
@Test
public void sendSimpleMessage() throws Exception {

    AmazonSimpleEmailServiceClient sesClient = provider.getClient();
    Assume.assumeNotNull("AWS client not null", sesClient);

    WildFlyCamelContext camelctx = new WildFlyCamelContext();
    camelctx.getNamingContext().bind("sesClient", sesClient);

    camelctx.addRoutes(new RouteBuilder() {
        public void configure() {
            from("direct:start")
            .to("aws-ses://" + SESUtils.FROM + "?amazonSESClient=#sesClient");
        }
    });

    camelctx.start();
    try {
        Exchange exchange = ExchangeBuilder.anExchange(camelctx)
                .withHeader(SesConstants.SUBJECT, SESUtils.SUBJECT)
                .withHeader(SesConstants.TO, Collections.singletonList(SESUtils.TO))
                .withBody("Hello world!")
                .build();

        ProducerTemplate producer = camelctx.createProducerTemplate();
        Exchange result = producer.send("direct:start", exchange);

        String messageId = result.getIn().getHeader(SesConstants.MESSAGE_ID, String.class);
        Assert.assertNotNull("MessageId not null", messageId);

    } finally {
        camelctx.stop();
    }
}
项目:wildfly-camel    文件:SESUtils.java   
public static AmazonSimpleEmailServiceClient createEmailClient() {
    BasicCredentialsProvider credentials = BasicCredentialsProvider.standard();
    AmazonSimpleEmailServiceClient client = !credentials.isValid() ? null : (AmazonSimpleEmailServiceClient)
            AmazonSimpleEmailServiceClientBuilder.standard()
            .withCredentials(credentials)
            .withRegion("eu-west-1")
            .build();
    return client;
}
项目:tdl-auth    文件:Mailer.java   
public AmazonSimpleEmailService createClient() {
    return AmazonSimpleEmailServiceClient
            .builder()
            .withRegion(Regions.US_EAST_1)
            .build();
}
项目:kodokojo    文件:SesEmailSender.java   
@Override
public void send(List<String> to, List<String> cc, List<String> ci, String object, String content, boolean htmlContent, Set<Attachment> attachments) {
    if (CollectionUtils.isEmpty(to)) {
        throw new IllegalArgumentException("to must be defined.");
    }
    if (isBlank(content)) {
        throw new IllegalArgumentException("content must be defined.");
    }

    if (attachments == null) {
        sendSimpleMail(to, cc, ci, object, content, htmlContent);
    } else {
        Session session = Session.getDefaultInstance(new Properties());
        MimeMessage message = new MimeMessage(session);
        try {
            message.setSubject(object);
            message.setFrom(new InternetAddress(from));
            addRecipients(message, javax.mail.Message.RecipientType.TO, to);
            addRecipients(message, javax.mail.Message.RecipientType.CC, cc);
            addRecipients(message, javax.mail.Message.RecipientType.BCC, ci);

            MimeBodyPart wrap = new MimeBodyPart();
            MimeMultipart cover = new MimeMultipart("alternative");
            MimeBodyPart html = new MimeBodyPart();
            cover.addBodyPart(html);

            wrap.setContent(cover);

            MimeMultipart multiPartContent = new MimeMultipart("related");
            message.setContent(multiPartContent);
            multiPartContent.addBodyPart(wrap);

            for (Attachment attachment : attachments) {

                MimeBodyPart attachmentPart = new MimeBodyPart();

                attachmentPart.setHeader("Content-ID", "<" + attachment.getId() + ">");
                attachmentPart.setFileName(attachment.getFileName());
                attachmentPart.setContent(attachment.getContent(), attachment.mineType());

                multiPartContent.addBodyPart(attachmentPart);
            }

            html.setContent(content, MINE_TEXT_HTML);

            // Send the email.
            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            message.writeTo(outputStream);
            RawMessage rawMessage = new RawMessage(ByteBuffer.wrap(outputStream.toByteArray()));

            SendRawEmailRequest rawEmailRequest = new SendRawEmailRequest(rawMessage);

            AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient();
            client.setRegion(region);

            client.sendRawEmail(rawEmailRequest);

        } catch (MessagingException | IOException e) {
            e.printStackTrace();
        }
    }
}
项目:ExerciseMe    文件:AmazonClientManager.java   
public AmazonSimpleEmailServiceClient ses() {
    validateCredentials();
    return sesClient;
}
项目:spring-cloud-aws    文件:MailSenderAutoConfiguration.java   
@Bean
@ConditionalOnMissingAmazonClient(AmazonSimpleEmailService.class)
public AmazonWebserviceClientFactoryBean<AmazonSimpleEmailServiceClient> amazonSimpleEmailService(AWSCredentialsProvider credentialsProvider) {
    return new AmazonWebserviceClientFactoryBean<>(AmazonSimpleEmailServiceClient.class,
            credentialsProvider, this.regionProvider);
}
项目:spring-cloud-aws    文件:SimpleEmailServiceBeanDefinitionParserTest.java   
private static String getEndpointUrlFromWebserviceClient(AmazonSimpleEmailServiceClient client) throws Exception {
    Field field = findField(AmazonSimpleEmailServiceClient.class, "endpoint");
    makeAccessible(field);
    URI endpointUri = (URI) field.get(client);
    return endpointUri.toASCIIString();
}
项目:wildfly-camel    文件:SESClientProducer.java   
SESClientProvider(AmazonSimpleEmailServiceClient client) {
    this.client = client;
}
项目:wildfly-camel    文件:SESClientProducer.java   
public AmazonSimpleEmailServiceClient getClient() {
    return client;
}
项目:wildfly-camel    文件:SESClientProducer.java   
@Produces
@Singleton
public SESClientProvider getClientProvider() throws Exception {
    AmazonSimpleEmailServiceClient client = SESUtils.createEmailClient();
    return new SESClientProvider(client);
}