如何使用入站解析捕获OOO(不在办公室)电子邮件?

时间:2017-01-06 17:38:04

标签: java email sendgrid mailgun

我的应用程序将电子邮件发送到联系人列表,我想捕获OOO(外出)电子邮件,以自动检测谁正在休假,并(希望)根据消息发现他/她回来了。我正在尝试使用Sendgrid和Mailgun的入站解析功能来做到这一点。

两者都有相同的行为:当我手动发送电子邮件时它们工作正常,但由于某种原因它们忽略了自动响应OOO消息。有没有人知道发生了什么?

在这两种情况下,我都在使用java库。以下是代码段:

Mailgun:

@Test
public void shouldSendEmailUsingMailgun() throws Exception {
    Configuration configuration = new Configuration()
            .domain("<my_domain>")
            .apiKey("<my_api_key>")
            .from("<from>", "no-reply@subdomain.domain.com");

    Mail.using(configuration)
            .to("john@subdomain.domain.com")
            .subject("Mailgun testing OOO with reply-to")
            .text("Hello, from Mailgun")
            .replyTo("ooo@smartcanvas.com")
            .build()
            .send();

}

Sendgrid

    Email from = new Email("no-reply@subdomain.domain.com");
    String subject = "This is a test announcement from ooo detection";
    Email to = new Email("<recipient>");
    Content content = new Content("text/plain", "Hello, Email!");
    Mail mail = new Mail(from, subject, to, content);
    Email replyTo = new Email("no-reply@subdomain.domain.com");
    mail.setReplyTo(replyTo);


    SendGrid sg = new SendGrid("<api_key>");
    Request request = new Request();

    try {
        request.method = Method.POST;
        request.endpoint = "mail/send";
        request.body = mail.build();
        Response response = sg.api(request);
        System.out.println(response.statusCode);
        System.out.println(response.body);
        System.out.println(response.headers);
    } catch (IOException ex) {
        throw ex;
    }

谢谢!

1 个答案:

答案 0 :(得分:0)

您可能希望查看功能更全面的入站解析器,例如Mailparser.io 我不熟悉Mailgun的实现,但SendGrid的Parse实现非常基础。它应该将OOO响应发送到您的端点,假设它已正确配置,但它没有逻辑来解析正文,所以你必须自己这样做。