Search in sources :

Example 1 with SendEmailRequest

use of com.amazonaws.services.simpleemail.model.SendEmailRequest in project camel by apache.

the class SesComponentSpringTest method sendInOnlyMessageUsingUrlOptions.

@Test
public void sendInOnlyMessageUsingUrlOptions() throws Exception {
    Exchange exchange = template.send("direct:start", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setBody("This is my message text.");
        }
    });
    assertEquals("1", exchange.getIn().getHeader(SesConstants.MESSAGE_ID));
    SendEmailRequest sendEmailRequest = sesClient.getSendEmailRequest();
    assertEquals("from@example.com", sendEmailRequest.getSource());
    assertEquals(2, getTo(sendEmailRequest).size());
    assertTrue(getTo(sendEmailRequest).contains("to1@example.com"));
    assertTrue(getTo(sendEmailRequest).contains("to2@example.com"));
    assertEquals("bounce@example.com", sendEmailRequest.getReturnPath());
    assertEquals(2, sendEmailRequest.getReplyToAddresses().size());
    assertTrue(sendEmailRequest.getReplyToAddresses().contains("replyTo1@example.com"));
    assertTrue(sendEmailRequest.getReplyToAddresses().contains("replyTo2@example.com"));
    assertEquals("Subject", getSubject(sendEmailRequest));
    assertEquals("This is my message text.", getBody(sendEmailRequest));
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) SendEmailRequest(com.amazonaws.services.simpleemail.model.SendEmailRequest) Test(org.junit.Test)

Example 2 with SendEmailRequest

use of com.amazonaws.services.simpleemail.model.SendEmailRequest in project camel by apache.

the class SesProducer method createMailRequest.

private SendEmailRequest createMailRequest(Exchange exchange) {
    SendEmailRequest request = new SendEmailRequest();
    request.setSource(determineFrom(exchange));
    request.setDestination(determineTo(exchange));
    request.setReturnPath(determineReturnPath(exchange));
    request.setReplyToAddresses(determineReplyToAddresses(exchange));
    request.setMessage(createMessage(exchange));
    return request;
}
Also used : SendEmailRequest(com.amazonaws.services.simpleemail.model.SendEmailRequest)

Example 3 with SendEmailRequest

use of com.amazonaws.services.simpleemail.model.SendEmailRequest in project SimianArmy by Netflix.

the class AWSEmailNotifier method sendEmail.

@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;
    }
    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));
}
Also used : Destination(com.amazonaws.services.simpleemail.model.Destination) Message(com.amazonaws.services.simpleemail.model.Message) Content(com.amazonaws.services.simpleemail.model.Content) SendEmailResult(com.amazonaws.services.simpleemail.model.SendEmailResult) Body(com.amazonaws.services.simpleemail.model.Body) SendEmailRequest(com.amazonaws.services.simpleemail.model.SendEmailRequest)

Example 4 with SendEmailRequest

use of com.amazonaws.services.simpleemail.model.SendEmailRequest in project camel by apache.

the class SesProducer method process.

public void process(Exchange exchange) throws Exception {
    if (!(exchange.getIn().getBody() instanceof javax.mail.Message)) {
        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());
    } else {
        SendRawEmailRequest request = createRawMailRequest(exchange);
        log.trace("Sending request [{}] from exchange [{}]...", request, exchange);
        SendRawEmailResult result = getEndpoint().getSESClient().sendRawEmail(request);
        log.trace("Received result [{}]", result);
        Message message = getMessageForResponse(exchange);
        message.setHeader(SesConstants.MESSAGE_ID, result.getMessageId());
    }
}
Also used : Message(org.apache.camel.Message) SendRawEmailResult(com.amazonaws.services.simpleemail.model.SendRawEmailResult) SendRawEmailRequest(com.amazonaws.services.simpleemail.model.SendRawEmailRequest) SendEmailResult(com.amazonaws.services.simpleemail.model.SendEmailResult) SendEmailRequest(com.amazonaws.services.simpleemail.model.SendEmailRequest)

Example 5 with SendEmailRequest

use of com.amazonaws.services.simpleemail.model.SendEmailRequest in project camel by apache.

the class SesComponentSpringTest method sendMessageUsingMessageHeaders.

@Test
public void sendMessageUsingMessageHeaders() throws Exception {
    Exchange exchange = template.send("direct:start", new Processor() {

        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setBody("This is my message text.");
            exchange.getIn().setHeader(SesConstants.FROM, "anotherFrom@example.com");
            exchange.getIn().setHeader(SesConstants.TO, Arrays.asList("anotherTo1@example.com", "anotherTo2@example.com"));
            exchange.getIn().setHeader(SesConstants.RETURN_PATH, "anotherBounce@example.com");
            exchange.getIn().setHeader(SesConstants.REPLY_TO_ADDRESSES, Arrays.asList("anotherReplyTo1@example.com", "anotherReplyTo2@example.com"));
            exchange.getIn().setHeader(SesConstants.SUBJECT, "anotherSubject");
        }
    });
    assertEquals("1", exchange.getIn().getHeader(SesConstants.MESSAGE_ID));
    SendEmailRequest sendEmailRequest = sesClient.getSendEmailRequest();
    assertEquals("anotherFrom@example.com", sendEmailRequest.getSource());
    assertEquals(2, getTo(sendEmailRequest).size());
    assertTrue(getTo(sendEmailRequest).contains("anotherTo1@example.com"));
    assertTrue(getTo(sendEmailRequest).contains("anotherTo2@example.com"));
    assertEquals("anotherBounce@example.com", sendEmailRequest.getReturnPath());
    assertEquals(2, sendEmailRequest.getReplyToAddresses().size());
    assertTrue(sendEmailRequest.getReplyToAddresses().contains("anotherReplyTo1@example.com"));
    assertTrue(sendEmailRequest.getReplyToAddresses().contains("anotherReplyTo2@example.com"));
    assertEquals("anotherSubject", getSubject(sendEmailRequest));
    assertEquals("This is my message text.", getBody(sendEmailRequest));
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) SendEmailRequest(com.amazonaws.services.simpleemail.model.SendEmailRequest) Test(org.junit.Test)

Aggregations

SendEmailRequest (com.amazonaws.services.simpleemail.model.SendEmailRequest)7 Exchange (org.apache.camel.Exchange)4 Processor (org.apache.camel.Processor)4 Test (org.junit.Test)4 SendEmailResult (com.amazonaws.services.simpleemail.model.SendEmailResult)2 Body (com.amazonaws.services.simpleemail.model.Body)1 Content (com.amazonaws.services.simpleemail.model.Content)1 Destination (com.amazonaws.services.simpleemail.model.Destination)1 Message (com.amazonaws.services.simpleemail.model.Message)1 SendRawEmailRequest (com.amazonaws.services.simpleemail.model.SendRawEmailRequest)1 SendRawEmailResult (com.amazonaws.services.simpleemail.model.SendRawEmailResult)1 Message (org.apache.camel.Message)1