Example usage for com.amazonaws.services.simpleemail.model SendEmailResult getMessageId

List of usage examples for com.amazonaws.services.simpleemail.model SendEmailResult getMessageId

Introduction

In this page you can find the example usage for com.amazonaws.services.simpleemail.model SendEmailResult getMessageId.

Prototype


public String getMessageId() 

Source Link

Document

The unique message identifier returned from the SendEmail action.

Usage

From source file:com.adeptj.modules.aws.ses.api.AwsSesAsyncHandler.java

License:Apache License

@Override
default void onSuccess(SendEmailRequest request, SendEmailResult result) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Email sent to: {}", request.getDestination().getToAddresses());
        LOGGER.debug("SES SendEmailResult messageId: [{}]", result.getMessageId());
    }/*from w w w  . j a  v a  2 s.  c  om*/
}

From source file:com.adeptj.modules.aws.ses.internal.AwsSesService.java

License:Apache License

/**
 * {@inheritDoc}//from  w  ww  .  j  a  v  a  2 s  .c o  m
 */
@Override
public EmailResponse sendEmail(EmailRequest emailRequest) {
    try {
        SendEmailResult result = this.asyncSES
                .sendEmail(new SendEmailRequest().withSource(this.emailConfig.from())
                        .withDestination(new Destination().withToAddresses(emailRequest.getRecipientToList())
                                .withCcAddresses(emailRequest.getRecipientCcList())
                                .withBccAddresses(emailRequest.getRecipientBccList()))
                        .withMessage(new Message()
                                .withSubject(new Content().withData(emailRequest.getSubject())).withBody(
                                        new Body().withHtml(new Content().withData(emailRequest.getBody())))));
        return new EmailResponse(result.getMessageId(), result.getSdkHttpMetadata().getHttpStatusCode(),
                result.getSdkHttpMetadata().getHttpHeaders());
    } catch (Exception ex) {
        LOGGER.error("Exception while sending email!!", ex);
        throw new AwsException(ex.getMessage(), ex);
    }
}

From source file:com.irurueta.server.commons.email.AWSMailSender.java

License:Apache License

/**
 * Method to send a text email.//from   ww w . j a  v a2  s . c o  m
 * @param m email message to be sent.
 * @return id of message that has been sent.
 * @throws MailNotSentException if mail couldn't be sent.
 */
private String sendTextEmail(AWSTextEmailMessage m) throws MailNotSentException {
    String messageId;
    long currentTimestamp = System.currentTimeMillis();
    prepareClient();
    if (!mEnabled) {
        //don't send message if not enabled
        return null;
    }

    try {
        synchronized (this) {
            //prevents throttling
            checkQuota(currentTimestamp);

            Destination destination = new Destination(m.getTo());
            if (m.getBCC() != null && !m.getBCC().isEmpty()) {
                destination.setBccAddresses(m.getBCC());
            }
            if (m.getCC() != null && !m.getCC().isEmpty()) {
                destination.setCcAddresses(m.getCC());
            }

            //if no subject, set to empty string to avoid errors
            if (m.getSubject() == null) {
                m.setSubject("");
            }

            Message message = new Message();
            m.buildContent(message);

            SendEmailResult result = mClient
                    .sendEmail(new SendEmailRequest(mMailFromAddress, destination, message));
            messageId = result.getMessageId();
            //update timestamp of last sent email
            mLastSentMailTimestamp = System.currentTimeMillis();

            //wait to avoid throwttling exceptions to avoid making any
            //further requests
            this.wait(mWaitIntervalMillis);
        }
    } catch (Throwable t) {
        throw new MailNotSentException(t);
    }
    return messageId;
}

From source file:com.mhp.insideApp.insideApplications.utils.SendMailHelperBean.java

private String assembleAndSend(Message message, String custEmailTO, String from) throws Exception {
    log.debug("Cust Email Id:-" + custEmailTO + "  Verified Email Id is :- " + from);
    Destination destination = new Destination().withToAddresses(custEmailTO);
    // Assemble the email.
    SendEmailRequest request = new SendEmailRequest().withSource(from).withDestination(destination)
            .withMessage(message);//from   w ww . j a  va  2 s.  c  o  m
    try {
        log.info("Attempting to send an email!");
        Region reg = Region.getRegion(Regions.fromName(region));
        amazonSimpleEmailServiceClient.setRegion(reg);
        // Send the email.
        SendEmailResult sendEmailResult = amazonSimpleEmailServiceClient.sendEmail(request);
        log.info("Email sent!");
        return sendEmailResult.getMessageId();
    } catch (Exception ex) {
        log.error("Error while sending the email", ex);
        throw new Exception(ex);
    }
}

From source file:com.netflix.simianarmy.aws.AWSEmailNotifier.java

License:Apache License

@Override
public void sendEmail(String to, String subject, String body) {
    if (!isValidEmail(to)) {
        LOGGER.error(String.format("The destination email address %s is not valid,  no email is sent.", to));
        return;/* w ww .  j  a va  2 s .  c om*/
    }
    if (sesClient == null) {
        String msg = "The email client is not set.";
        LOGGER.error(msg);
        throw new RuntimeException(msg);
    }
    Destination destination = new Destination().withToAddresses(to).withCcAddresses(getCcAddresses(to));
    Content subjectContent = new Content(subject);
    Content bodyContent = new Content();
    Body msgBody = new Body(bodyContent);
    msgBody.setHtml(new Content(body));
    Message msg = new Message(subjectContent, msgBody);
    String sourceAddress = getSourceAddress(to);
    SendEmailRequest request = new SendEmailRequest(sourceAddress, destination, msg);
    request.setReturnPath(sourceAddress);
    LOGGER.debug(String.format("Sending email with subject '%s' to %s", subject, to));
    SendEmailResult result = null;
    try {
        result = sesClient.sendEmail(request);
    } catch (Exception e) {
        throw new RuntimeException(String.format("Failed to send email to %s", to), e);
    }
    LOGGER.info(
            String.format("Email to %s, result id is %s, subject is %s", to, result.getMessageId(), subject));
}

From source file:com.streamreduce.core.service.EmailServiceImpl.java

License:Apache License

private String internalSendEmail(String to, String from, String replyTo, String subject, String htmlBody,
        String textBody) {//ww  w.  jav a  2  s . co  m
    SendEmailRequest request = new SendEmailRequest().withSource(from).withReplyToAddresses(replyTo);

    List<String> toAddresses = new ArrayList<>();
    toAddresses.add(to);

    Destination dest = new Destination().withToAddresses(toAddresses);
    request.setDestination(dest);

    Content subjContent = new Content().withData(subject);
    Message msg = new Message().withSubject(subjContent);

    // Include a body in both text and HTML formats
    Body theBody = new Body();
    if (textBody != null) {
        theBody.withText(new Content().withData(textBody));
    }
    if (htmlBody != null) {
        theBody.withHtml(new Content().withData(htmlBody));
    }
    msg.setBody(theBody);

    request.setMessage(msg);

    // Call Amazon SES to send the message
    String messageId = null;
    try {
        SendEmailResult result = simpleEmailServiceClient.sendEmail(request);
        messageId = result.getMessageId();
    } catch (AmazonClientException e) {
        logger.debug("[SES EMAIL] AWS AmazonClientException " + e.getMessage());
        logger.error("Caught an AddressException, which means one or more of your "
                + "addresses are improperly formatted." + e.getMessage());
    } catch (Exception e) {
        logger.debug("[SES EMAIL] AWS General Exception " + e.getMessage());
    }
    return messageId;
}

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

License:Apache License

public static void main(String argv[]) {

    String host = "cmcdomain";
    String mailFrom = "no-reply@cmcdomain";
    String mailTo = "yourname@yourdomain";

    // Construct an object to contain the recipient address.
    Destination destination = new Destination().withToAddresses(new String[] { mailTo });

    // Create the subject and body of the message.
    Content subject = new Content().withData("test mail");
    Content textBody = new Content().withData("test message");
    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(mailFrom).withDestination(destination)
            .withMessage(message);//w  w  w  .j a va2 s.c o m

    System.out.println("send start");
    CMCAmazonClient client = new CMCAmazonClient(host);
    SendEmailResult result = client.sendEmail(request);
    System.out.println("message id=" + result.getMessageId());
    System.out.println("send end");
}

From source file:org.apache.camel.component.aws.ses.SesProducer.java

License:Apache License

public void process(Exchange exchange) throws Exception {
    SendEmailRequest request = createMailRequest(exchange);
    log.trace("Sending request [{}] from exchange [{}]...", request, exchange);

    SendEmailResult result = getEndpoint().getSESClient().sendEmail(request);

    log.trace("Received result [{}]", result);
    Message message = getMessageForResponse(exchange);
    message.setHeader(SesConstants.MESSAGE_ID, result.getMessageId());
}

From source file:org.springframework.cloud.aws.mail.simplemail.SimpleEmailServiceMailSender.java

License:Apache License

@SuppressWarnings("OverloadedVarargsMethod")
@Override//from   w w  w  .j a  v a  2 s .c om
public void send(SimpleMailMessage... simpleMailMessages) throws MailException {

    Map<Object, Exception> failedMessages = new HashMap<>();

    for (SimpleMailMessage simpleMessage : simpleMailMessages) {
        try {
            SendEmailResult sendEmailResult = getEmailService().sendEmail(prepareMessage(simpleMessage));
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Message with id: {0} successfully send", sendEmailResult.getMessageId());
            }
        } catch (AmazonClientException e) {
            //Ignore Exception because we are collecting and throwing all if any
            //noinspection ThrowableResultOfMethodCallIgnored
            failedMessages.put(simpleMessage, e);
        }
    }

    if (!failedMessages.isEmpty()) {
        throw new MailSendException(failedMessages);
    }
}