Search in sources :

Example 1 with SendRawEmailRequest

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

the class SesComponentSpringTest method sendRawMessage.

@Test
public void sendRawMessage() throws Exception {
    final MockMessage mess = new MockMessage();
    Exchange exchange = template.request("direct:start", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setBody(mess);
        }
    });
    assertEquals("1", exchange.getOut().getHeader(SesConstants.MESSAGE_ID));
    SendRawEmailRequest sendRawEmailRequest = sesClient.getSendRawEmailRequest();
    assertEquals("from@example.com", sendRawEmailRequest.getSource());
    assertEquals(2, getTo(sendRawEmailRequest).size());
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) SendRawEmailRequest(com.amazonaws.services.simpleemail.model.SendRawEmailRequest) Test(org.junit.Test)

Example 2 with SendRawEmailRequest

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

the class SesProducer method createRawMailRequest.

private SendRawEmailRequest createRawMailRequest(Exchange exchange) throws Exception {
    SendRawEmailRequest request = new SendRawEmailRequest();
    request.setSource(determineFrom(exchange));
    request.setDestinations(determineRawTo(exchange));
    request.setRawMessage(createRawMessage(exchange));
    return request;
}
Also used : SendRawEmailRequest(com.amazonaws.services.simpleemail.model.SendRawEmailRequest)

Example 3 with SendRawEmailRequest

use of com.amazonaws.services.simpleemail.model.SendRawEmailRequest 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 4 with SendRawEmailRequest

use of com.amazonaws.services.simpleemail.model.SendRawEmailRequest in project ice by Netflix.

the class BasicWeeklyCostEmailService method sendEmail.

private void sendEmail(boolean test, AmazonSimpleEmailServiceClient emailService, String email, List<ApplicationGroup> appGroups) throws IOException, MessagingException {
    StringBuilder body = new StringBuilder();
    body.append("<html><head><style type=\"text/css\">a:link, a:visited{color:#006DBA;}a:link, a:visited, a:hover {\n" + "text-decoration: none;\n" + "}\n" + "body {\n" + "color: #333;\n" + "}" + "</style></head>");
    List<MimeBodyPart> mimeBodyParts = Lists.newArrayList();
    int index = 0;
    String subject = "";
    for (ApplicationGroup appGroup : appGroups) {
        boolean hasData = false;
        for (String prodName : appGroup.data.keySet()) {
            if (config.productService.getProductByName(prodName) == null)
                continue;
            hasData = appGroup.data.get(prodName) != null && appGroup.data.get(prodName).size() > 0;
            if (hasData)
                break;
        }
        if (!hasData)
            continue;
        try {
            MimeBodyPart mimeBodyPart = constructEmail(index, appGroup, body);
            index++;
            if (mimeBodyPart != null) {
                mimeBodyParts.add(mimeBodyPart);
                subject = subject + (subject.length() > 0 ? ", " : "") + appGroup.getDisplayName();
            }
        } catch (Exception e) {
            logger.error("Error contructing email", e);
        }
    }
    body.append("</html>");
    if (mimeBodyParts.size() == 0)
        return;
    DateTime end = new DateTime(DateTimeZone.UTC).withDayOfWeek(1).withMillisOfDay(0);
    subject = String.format("%s Weekly AWS Costs (%s - %s)", subject, formatter.print(end.minusWeeks(1)), formatter.print(end));
    String toEmail = test ? testEmail : email;
    Session session = Session.getInstance(new Properties());
    MimeMessage mimeMessage = new MimeMessage(session);
    mimeMessage.setSubject(subject);
    mimeMessage.setRecipients(javax.mail.Message.RecipientType.TO, toEmail);
    if (!test && !StringUtils.isEmpty(bccEmail)) {
        mimeMessage.addRecipients(Message.RecipientType.BCC, bccEmail);
    }
    MimeMultipart mimeMultipart = new MimeMultipart();
    BodyPart p = new MimeBodyPart();
    p.setContent(body.toString(), "text/html");
    mimeMultipart.addBodyPart(p);
    for (MimeBodyPart mimeBodyPart : mimeBodyParts) mimeMultipart.addBodyPart(mimeBodyPart);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    mimeMessage.setContent(mimeMultipart);
    mimeMessage.writeTo(outputStream);
    RawMessage rawMessage = new RawMessage(ByteBuffer.wrap(outputStream.toByteArray()));
    SendRawEmailRequest rawEmailRequest = new SendRawEmailRequest(rawMessage);
    rawEmailRequest.setDestinations(Lists.<String>newArrayList(toEmail));
    rawEmailRequest.setSource(fromEmail);
    logger.info("sending email to " + toEmail + " " + body.toString());
    emailService.sendRawEmail(rawEmailRequest);
}
Also used : MimeBodyPart(javax.mail.internet.MimeBodyPart) BodyPart(javax.mail.BodyPart) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MessagingException(javax.mail.MessagingException) IOException(java.io.IOException) DateTime(org.joda.time.DateTime) ApplicationGroup(com.netflix.ice.reader.ApplicationGroup) MimeMessage(javax.mail.internet.MimeMessage) MimeMultipart(javax.mail.internet.MimeMultipart) SendRawEmailRequest(com.amazonaws.services.simpleemail.model.SendRawEmailRequest) MimeBodyPart(javax.mail.internet.MimeBodyPart) RawMessage(com.amazonaws.services.simpleemail.model.RawMessage) Session(javax.mail.Session)

Aggregations

SendRawEmailRequest (com.amazonaws.services.simpleemail.model.SendRawEmailRequest)4 RawMessage (com.amazonaws.services.simpleemail.model.RawMessage)1 SendEmailRequest (com.amazonaws.services.simpleemail.model.SendEmailRequest)1 SendEmailResult (com.amazonaws.services.simpleemail.model.SendEmailResult)1 SendRawEmailResult (com.amazonaws.services.simpleemail.model.SendRawEmailResult)1 ApplicationGroup (com.netflix.ice.reader.ApplicationGroup)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 BodyPart (javax.mail.BodyPart)1 MessagingException (javax.mail.MessagingException)1 Session (javax.mail.Session)1 MimeBodyPart (javax.mail.internet.MimeBodyPart)1 MimeMessage (javax.mail.internet.MimeMessage)1 MimeMultipart (javax.mail.internet.MimeMultipart)1 Exchange (org.apache.camel.Exchange)1 Message (org.apache.camel.Message)1 Processor (org.apache.camel.Processor)1 DateTime (org.joda.time.DateTime)1 Test (org.junit.Test)1