How to receive bounced mail using AWS SES With Postfix
Asked Answered
A

3

7

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
Angelenaangeleno answered 12/6, 2014 at 8:27 Comment(0)
S
1

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

^_^

Superload answered 14/6, 2017 at 16:7 Comment(0)
B
0

In order to received the bound message, you must set an envelope sender address which is delivered locally on your postfix installation.

Check

   postconf mydestination

to see which domains are delivered locally. Your application then needs to set the envelope sender address to a valid, locally delivered address. Something like [email protected]

Burbank answered 29/12, 2016 at 13:42 Comment(0)
H
0

You can't convince postfix to fill out the MAIL FROM with anything other than <> because it is hardcoded.

What you can do is enable double-bounce notifications in main.cf:

# enable double bounce notifications (resource, software are the defaults)
notify_classes = 2bounce, resource, software

# Set the sender address for 2bounce
# @myhostname will be appended even if you have an @ in the sender
double_bounce_sender = postmaster

# Set the recipient address for 2bounce
2bounce_notice_recipient = [email protected]
# (and resource, software)
error_notice_recipient = [email protected]

You'll end up with something like this.

PHP app (From: <[email protected]>) --> SES (To: <[email protected]>) 
: 5xx Rejected 

Postfix (From: <>) -> SES (<[email protected]>)
: 501 Rejected Invalid MAIL FROM

Postfix (From: <[email protected]>) -> SES (<[email protected]>)

Whilst this strictly answers the question in that bounce messages will sort of be attempted via SES, it's worth noting that in the situation where e-mail one failed due to configuration problems, this is not necessarily more useful than setting bounce recipient to a local mailbox as suggested in the other answers - the 2bounce mail would be subject to the same configuration issues and would presumably also not be able to be sent.

Hetero answered 19/11, 2021 at 3:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.