【问题标题】:Bounced mails get Status header退回的邮件获取状态标头
【发布时间】:2021-08-22 06:53:01
【问题描述】:

我正在尝试读取退回电子邮件的状态标题。 This site 更好地解释了我正在尝试的内容...

原来的email是由几个MultiParts对象组成的,所以我是用java代码看的:

 private void test(MimeMessage message) throws IOException, MessagingException {
    if (message.getContent() != null && message.getContent() instanceof Multipart) {
                    Multipart content = (Multipart) message.getContent();
                    for (int i = 0; i < content.getCount(); i++) {
                        BodyPart bodyPart = content.getBodyPart(i);
                        Enumeration headers = bodyPart.getAllHeaders();
                        while(headers.hasMoreElements()){
                            Header header = (Header) headers.nextElement();
                            LOGGER.info("Header: " + header.getName() + " value: " + header.getValue());
                        }
                    }

                }
}

我正在分析的电子邮件部分:

Content-Description:交付报告 Content-Type:text/plain; charset=utf-8 内容传输编码:7bit

报告-MTA:dns; someLink.com X-Postfix-Queue-ID:EC862F00D0 X-Postfix-Sender:rfc822; receiver@email.com 到达日期:2013 年 8 月 7 日,星期三 13:52:43 +0200 (CEST)

最终收件人:rfc822; noexisting@email.com 原始收件人:rfc822;noexisting@email.com 行动: 失败状态:5.1.1 远程 MTA:dns; [somelink.com 诊断代码:smtp; 550-5.1.1 您尝试使用的电子邮件帐户 到达确实 不存在。请尝试 550-5.1.1 仔细检查收件人的电子邮件 地址错别字或 550-5.1.1 不必要的空格。

在我的日志文件中,我只能看到前 3 个标题:

> Header: Content-Description value: Delivery report   
> Header: Content-Type value: text/plain; charset=us-ascii INFO   
> Header: Content-Transfer-Encoding value: 7bit

有人知道为什么吗?我怎样才能获得状态标题?谢谢

【问题讨论】:

    标签: java smtp email-bounces


    【解决方案1】:

    我在标题中找不到状态信息,我将从内容中获取它。这不是一个优雅的解决方案,但至少它有效。 如果有人找到更好的,请告诉我!

    Java 代码:

    StringWriter writer = new StringWriter();
                    IOUtils.copy(bodyPart.getInputStream(), writer);
                    LOGGER.info("Content inputstream: " +  writer.toString());
    

    日志:

    内容输入流:报告-MTA:dns; srvvie-mx3.styria-multi-media.com X-Postfix-Queue-ID:2A1A8F00CF X-Postfix-Sender:rfc822; 抵达日期:2013 年 8 月 9 日星期五 11:14:02 +0200 (CEST)

    最终收件人:rfc822; MAILER-DAEMON@domain.com 原始收件人:rfc822;MAILER-DAEMON@domain.com 行动:失败状态:5.1.1 远程 MTA:dns; 诊断代码:smtp; 550 5.1.1 邮箱 不存在

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-02-24
      • 1970-01-01
      • 1970-01-01
      • 2015-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多