Because of problems of IP/domain reputation (my server and domain very recent), I had to use Amazon SES as SMTP relay to be able to not have my mails flagged as spam.

My setup with Amazon was working fine, but impossible for me to do mail forwarding using Amazon SMTP, because the adress of the FROM header must be verified.

What I decided to do is to only send through Amazon the mails directly sent from my server, and to just use my own SMTP for the forwarding stuff. (Because the mails are signed by other servers with good reputation, even if the mail is sent by my server, its not flagged as spam)

To do that, I used the following settings :

relayhost =
sender_dependent_relayhost_maps = hash:/etc/postfix/relayhost_maps

sender_canonical_maps = regexp:/etc/postfix/sender_canonical
sender_canonical_classes = envelope_sender
smtpd_data_restrictions = check_sender_access pcre:/etc/postfix/sender_access

relayhost_maps :

contact@domain1.tld [email-smtp.eu-west-1.amazonaws.com]:25
@domain2.tld [email-smtp.eu-west-1.amazonaws.com]:25
@domain3.tld [email-smtp.eu-west-1.amazonaws.com]:25
@domain4.tld [email-smtp.eu-west-1.amazonaws.com]:25
@domain5.tld [email-smtp.eu-west-1.amazonaws.com]:25

sender_canonical :

/.*/    no-reply@domain1.tld

sender_access :

/(.*)/  prepend X-Envelope-From: <$1>

I'm relaying all the mails of my domain through amazon, except for domain1 which will be used for forwarding with the address no-reply@domain1.tld. I need to rewrite the envelope address, to be able to forward the mails.

My problem is that I would like to rewrite the envelope address only for the mails coming from outside of my server that I forward to external webmail. All the mails sent directly from my users webmails have to go through Amazon.


After more research, it seems like the way to do what I want is to use regexp in the the sender_canonical file.

I tried to write the following expression, but it seems there is something wrong.

/^((?!@domain1.tld)(?!@domain2.tld)(?!@domain3.tld)(?!@domain4.tld)(?!@domain5.tld).)*$/gm no-reply@domain1.tld

EDIT : I finally found the correct way to write the expression :

!/@domain1.tld|@domain2.tld|@domain3.tld|@domain4.tld|@domain5.tld/    no-reply@domain1.tld

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.