All my mails are received by my own mail server and are then forwarded to my Google account (as I am using Google Mail as my mail client). Unfortunately if you just forward mails with POSTFIX you might also forward incoming spam mails which Google does not like. It can be that Google thinks you are a spam sender and blacklist your server.

I have found this blog entry which describes a way to correctly set the envelope address of forwarded mails:

So in summary this is what I did:

[codesyntax lang=”bash”]
# download and compile the software
cd ~
wget https://github.com/roehling/postsrsd/archive/master.zip
unzip master
cd postsrsd-master/
make
sudo make install
[/codesyntax]

Then added the following lines to /etc/postfix/main.cf:

[codesyntax lang=”text”]
sender_canonical_maps = tcp:127.0.0.1:10001
sender_canonical_classes = envelope_sender
recipient_canonical_maps = tcp:127.0.0.1:10002
recipient_canonical_classes= envelope_recipient,header_recipient
[/codesyntax]

Then I started the SRS daemon and reloaded the POSTFIX configuration:

[codesyntax lang=”bash”]
# Start SRS daemon
sudo service postsrsd restart
#Reload postfix
sudo service postfix reload
[/codesyntax]

I did not need to add the SRS daemon to startup as it seems to be automatically started already.

As I forward all mail from my server to Expurgate/Spamfence for spam checking I also neeeded to add the Expurgate servers to my SPF domain record so that Google accepts mails sent by my mail server via Expurgate to Google. This is the PSF record I am using for my domain “urspringer.de”:

[codesyntax lang=”text”]
v=spf1 a mx a:mx.expurgate.net ip4:87.230.85.144 ip6:2a01:488:66:1000:57e6:5590:0:1 include:expurgate.net ~all
[/codesyntax]

Currently it seems to look fine as Google verifies the SPF record although the mails are forwarded twice:
[codesyntax lang=”text”]
Return-Path: <SRS0+WJa2=BP=googlemail.com=samoel2406@urspringer.de>
Received: from mx.expurgate.net (mx.expurgate.net. [194.145.224.20])
by mx.google.com with ESMTPS id ft4si45524597pdb.17.2014.12.27.06.00.52
for <michael.urspringer@gmail.com>
(version=TLSv1.2 cipher=RC4-SHA bits=128/128);
Sat, 27 Dec 2014 06:00:53 -0800 (PST)
Received-SPF: pass (google.com: domain of SRS0+WJa2=BP=googlemail.com=samoel2406@urspringer.de designates 194.145.224.20 as permitted sender) client-ip=194.145.224.20;
Authentication-Results: mx.google.com;
spf=pass (google.com: domain of SRS0+WJa2=BP=googlemail.com=samoel2406@urspringer.de designates 194.145.224.20 as permitted sender) smtp.mail=SRS0+WJa2=BP=googlemail.com=samoel2406@urspringer.de;
dkim=pass header.i=@googlemail.com
[/codesyntax]

Update:

If you cannot start the service in Debain 8 and higher () you need to enable the service first with
[codesyntax]
systemctl enable postsrsd
[/codesyntax]

Forwarding mails to Google Account
Tagged on:         

Leave a Reply

Your email address will not be published. Required fields are marked *