nodemailer / mailparser

Decode mime formatted e-mails
Other
1.59k stars 281 forks source link

Include the specific receiver of an email in a field #333

Closed henricook closed 1 year ago

henricook commented 1 year ago

Is your feature request related to a problem? Please describe. When an email is addressed to two or more people e.g. alice@blah.com, bob@blah.com, charlie@blah.com and I am parsing the email that one of them received, I'd like to know which one. Currently I can only get the contents of the to field which doesn't tell me who the receiver of this specific message is.

Describe the solution you'd like I thought that delivered-to might achieve this for me but it seems not. I can see that the data I want is in the received header and I could try and parse it out myself but I don't know if it's uniform and I'm hoping the creators of this library might 🙏🏻

For example, as above, when I'm looking at the email the Alice received with all three people in the to field, I can see in the email body:

    "headerLines": [
        {
            "key": "received",
            "line": "Received: from mail-oa1-f54.google.com (mail-oa1-f54.google.com [209.85.160.54])\r\n by inbound-smtp.eu-west-1.amazonaws.com with SMTP id ion5ng77iojod0lm5qc2eanghlmdbqrbfsrad601\r\n for alice@blah.com;\r\n Sat, 14 Jan 2023 17:19:21 +0000 (UTC)"
        },

I'd like to be able to know that the email I'm parsing was for alice@blah.com

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Add any other context or screenshots about the feature request here.

andris9 commented 1 year ago

The actual target address is only known in the SMTP context. It does not survive 100% for mail access. The best bet you have is:

  1. check the Delivered-To header (only an email address, nothing else)
  2. check the latest Recipient header (a complex structure that needs parsing. In most cases it does not include the recipient address, but sometimes it does).

So, in short, there is no 100% perfect way of detecting that address. If the recipient was a BCC address, then depending on the email servers, it might be that there is no indication whatsoever in the message about the recipient.