sisimai / p5-sisimai

Mail Analyzing Interface for email bounce: A Perl module to parse RFC5322 bounce mails and generating structured data as JSON from parsed results. Formerly known as bounceHammer 4: an error mail analyzer.
https://libsisimai.org
BSD 2-Clause "Simplified" License
76 stars 26 forks source link

How to obtain the original recipient when the bounce is originated in the final destination? #496

Closed anibalpacheco closed 6 months ago

anibalpacheco commented 1 year ago

I have this siuation:

Return-Path: <bounce_mx@mydomain.com>
Received: from other.domain1.com (other.domain1.com [x.x.x.x])
    by second_mta.domain1.com (Postfix) with ESMTPS id second_id
    for <example@domain2.com>; datetime1+13s
Received: from mail.domain1.com (unknown [x.x.y.y])
    by other.domain1.com (Postfix) with ESMTPS;
    datetime1+1s
Received: from my_mta.mydomain.com (my_mta.mydomain.com [z.z.z.z])
    by first_mta.domain1.com (Postfix) with ESMTP id first_id
    for <example@domain1.com>; datetime1

Can sisimai get the "example@domain1.com" info somehow? below is the json generated by sisimai (printed in Python and also with original data replaced):

{
'origin': '/var/mail/sisimaiuser',
'addresser': 'mailfrom@mydomain.com',
'diagnostictype': 'SMTP',
'rhost': 'smtp-in.domain2.com',
'messageid': '20230905234254.***@mta01.in.domain1.com',
'senderdomain': 'mydomain.com',
'timezoneoffset': '***',
'subject': 'the subject',
'smtpcommand': '',
'replycode': '550',
'lhost': '',
'destination': 'domain2.com',
'feedbacktype': '',
'smtpagent': 'RFC3464',
'diagnosticcode': "550-5.1.1 The email account that you tried to reach does not exist.....more info and a link",
'timestamp': ****,
'softbounce': 0,
'deliverystatus': '5.1.1',
'listid': 'mylistid.mydomain.com',
'reason': 'userunknown',
'catch': None,
'recipient': 'example@domain2.com',
'alias': '',
'token': '1006*****c',
'action': 'failed'
}

And this is the line used to generate it:

perl -MSisimai -lE 'print Sisimai->dump(shift)' /var/mail/sisimaiuser > bounces.json

thank you

azumakuniyuki commented 1 year ago

Hello,

In general, Sisimai substitutes the originating email address as the value of alias. For example, the parsed results of set-of-emails/maildir/bsd/lhost-sendmail-58.eml has alias field.

  {
    "diagnostictype": "SMTP",
    "timestamp": 1569822105,
    "feedbacktype": "",
    "diagnosticcode": "550-5.7.1 Unauthenticated email from cpanel.com is not accepted due to domain's DMARC policy. Please contact the administrator of cpanel.com domain if this was a legitimate mail. Please visit https://support.google.com/mail/answer/2451690 to learn about the DMARC initiative. y13si1773519pll.31 - gsmtp",
    "origin": "set-of-emails/maildir/bsd/lhost-sendmail-58.eml",
    "destination": "example.jp",
*** "alias": "kijitora+neko-nyaan@google.example.com",
    "reason": "policyviolation",
    "addresser": "cpanel@cpanel.com",
    "replycode": "550",
    "softbounce": 1,
    "token": "768e9bdfe4593b95a7924732adfa2f47f0944305",
    "action": "failed",
    "lhost": "no.rdns.hostshield.net",
    "catch": {
      "queue-id": "",
      "sender": "",
      "x-mailer": ""
    },
    "smtpcommand": "DATA",
    "smtpagent": "Sendmail",
    "rhost": "gmail-smtp-in.l.google.com",
    "deliverystatus": "5.7.1",
    "senderdomain": "cpanel.com",
    "messageid": "20190929224104.0E998710D86830E8@cpanel.com",
    "timezoneoffset": "+0900",
*** "recipient": "info@example.jp",
    "listid": "",
    "subject": "Suspension : Removal of cubicroot.jp from our server"
  }
]

The following lines related to alias are picked from the original bounce message:

Final-Recipient: RFC822; info@example.jp
X-Actual-Recipient: RFC822; kijitora+neko-nyaan@google.example.com
Action: failed
Status: 5.7.1
Remote-MTA: DNS; gmail-smtp-in.l.google.com
Diagnostic-Code: SMTP; 550-5.7.1 Unauthenticated email from cpanel.com is not accepted due to domain's
Last-Attempt-Date: Mon, 30 Sep 2019 14:41:45 +0900

However, the value of alias you post is empty. Perhaps, your bounce mail format may not be supported by Sisimai.

Would you provide the bounce mail (or a part of the bounce mail related to alias) to us?

Best regards,