Deliver Status Notification & Undelivered Mail Returned to Sender

dsnpostfix

daily I'm getting hundreds of these mails and have never been able to quite understand completely. Here are some high level types I have observed for these mails.

Type 1
From: Mail Delivery Subsystem (mailer-daemon@googlemail.com)
Subject: Delivery Status Notification (Delay)

Type 2
From: Mail Delivery Subsystem (mailer-daemon@googlemail.com)
Subject: Delivery Status Notification (Failure)

Type 3
From: Mail Delivery System (MAILER-DAEMON@www.mydomain.com)
Subject: Undelivered Mail Returned to Sender

Question Group 1
What puzzles me is for the DSNs from googlemail.com from Types 1 & 2 above, I'll see 3 mails from it with the following in the body of the mails in sequence over 3 days.
1) Message will be retried for 2 more day(s)
2) Message will be retried for 1 more day(s)
3) Delivery to the following recipient failed permanently

Questions are:
1) If the e-mail address doesn't exist on Google, why doesn't it tell me out right the address is not valid?
2) Assuming that it does exist because Google doesn't say outright on the initial try that it doesn't exist, why it'd still fail on the 3rd day saying "failed permanently"?

Question Group 2
Sometimes I'll be getting e-mails also from googlemail.com but these fall under Type 3 above. Content of the mail will include something like the following:
: host alt1.gmail-smtp-in.l.google.com[173.194.67.27]
said: 451 Requested action aborted: local error in processing (in reply to
RCPT TO command)

Questions:
1) Why wouldn't I see Google sending mails under Types 1 & 2 above ultimately telling me "Delivery to the following recipient failed permanently"?
2) What do I do in this case? Is this an invalid address or internal error with Google?

Question Group 3
Sometimes I'll also be getting e-mails with content "mailbox unavailable" from mails under Type 3 above. I'm running Dovecot / Postfix.

Question:
How do I make it such that I'll get a list of all the addresses resulted in "mailbox unavailable" so I can batch delete them from my system automatically?

Thanks!

Best Answer

There are some settings you may need to adjust in your postfix configuration, but first take into consideration the following facts:

1 - Postfix will try to deliver your emails for a certain amount of time and tries, once the limit is reached emails are marked as not delivered and generate the "type 3" email you describe above.

2 - A lot of servers out there impose a limit on the amount of emails they receive (or send) from (or to) a host by a given timeframe. If you try sending more emails than this limit it will generate a delay wich looks like email "type 1" you describe above.

3 - From time to time, a server will simply refuse to receive mail from other server for a number of reasons. In this cases you may receive an email that looks a lot like "Type 2"emails you describe.

Taking this into consideration, I'll try to answer your questions:

Group 1

1 - Telling the address is not valid makes it really easy to find wich emails do exist and harvest email lists (spam?). Just picture this, anyone may be able to generate millions of emails and test them to see if they exist.

2 - Have you considered that your server tried to send too much email to gmail, hit the limit, emails went to the deferred queue until they expire. You may consider checking your server's number of retries, time between retries, and expiration time.

Group 2

1 - Gmail's servers are refusing to talk to your server. Are you sending them too much email to non-existent accouns? perhaps spam?

2 - 451 in SMTP means an internal error, but it may be gmail just refusing to talk to your server.

Group 3

1 - This can be achieved by parsing the headers of the bounced emails.