Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to receive bounced mail using AWS SES With Postfix

I have configured postfix to relay mail to Amazon SES by following their integration guide and sending email is working without issue.

However, I recently wrote a PHP application using a framework which produced a malformed email message.

SES rejects the email with "554 Transaction failed: Expected MIME type, got =" which is acceptable.

However, my local postfix server then attempts to send a sender non-delivery notification with a from=<> which gets pushed through to the relay address.

SES rejects stating "501 Invalid MAIL FROM address provided (in reply to MAIL FROM command))" and postfix removes the bounce message from the queue.

Question is, what is the easier way to ensure I get the original 554 bounce message sent to me? I don't see a way to make the SES relay accept empty from fields, so I believe the solution would lay in configuring postfix to deliver the bounce message directly to me.

Note, I use the term 'bounced mail' perhaps incorrectly. The mail is perhaps rejected but I'm not sure of the correct nomenclature for this scenario. The key point is that the message is not accepted by the SES relay, so it hasn't in fact gone 'out the door' so to speak.

Jun 12 03:11:21 myserver postfix/smtp[6353]: 411BA21795: to=<[email protected]>, relay=email-smtp.us-east-1.amazonaws.com[54.243.192.132]:25, delay=0.29, delays=0.05/0.02/0.15/0.07, dsn=5.0.0, status=bounced (host email-smtp.us-east-1.amazonaws.com[54.243    .192.132] said: 554 Transaction failed: Expected MIME type, got = (in reply to end of DATA command))
Jun 12 03:11:21 myserver postfix/cleanup[6351]: 93F202179B: message-id=
Jun 12 03:11:21 myserver postfix/qmgr[895]: 93F202179B: from=<>, size=4673, nrcpt=1 (queue active)
Jun 12 03:11:21 myserver postfix/bounce[6354]: 411BA21795: sender non-delivery notification: 93F202179B
Jun 12 03:11:21 myserver postfix/qmgr[895]: 411BA21795: removed

Jun 12 03:11:21 myserver postfix/smtp[6353]: 93F202179B: to=<[email protected]>, relay=email-smtp.us-east-1.amazona    ws.com[23.21.161.144]:25, delay=0.17, delays=0.01/0/0.15/0, dsn=5.0.0, status=bounced (host email-smtp.us-east-1.amazonaws.com[23.    21.161.144] said: 501 Invalid MAIL FROM address provided (in reply to MAIL FROM command))
Jun 12 03:11:21 myserver postfix/qmgr[895]: 93F202179B: removed
like image 557
Andy Fusniak Avatar asked Jun 12 '14 08:06

Andy Fusniak


1 Answers

If you just need to get the Postfix bounce messages delivered to your inbox just set the next bounce related configuration params (/etc/postfix/main.cf file for Ubuntu):

# The list of error classes that are reported
notify_classes = bounce, delay, policy, protocol, resource, software

# The recipient of postmaster bounce notifications
bounce_notice_recipient = bounceuser

# The recipient of postmaster notifications about mail delivery problems that
# are caused by policy, resource, software or protocol errors.
error_notice_recipient = bounceuser

# The recipient of postmaster notifications with the message headers of mail
# that cannot be delivered within $delay_warning_time time units
delay_notice_recipient = bounceuser

bounceuser is the recipient that will get bounce related messages. If you need to forward the message to non-local recipient just edit /etc/aliases to make postfix forward the message to you:

# /dev/null will just delete the message from local
bounceuser: /dev/null, <YOUR_EMAIL_ADDRESS_HERE>

Don't forget to recreate the alias database and restart the postfix service:

sudo newaliases
sudo service postfix restart

^_^

like image 76
Nacho Coll Avatar answered Nov 15 '22 10:11

Nacho Coll