I've configured postfix to send through my gmail account. My /etc/aliases looks like this:

postmaster:    root
root:   my-email-address@gmail.com

When I test this using the following:

echo test | mail -s "test message" root

I receive the email in my gmail account as sent to root@localhost with my gmail account BCC'd.

I'd like to have it sent directly to my gmail account and not to the root@localhost.

What am I missing?



Applying the suggested virtual mapping I can see the effects at the BCC level but it is still BCC'ing rather than sending root email directly to the intended email address.

The main.cf change made is:

virtual_alias_domains = uberserver uberserver.home my-registered-domain.net
virtual_alias_maps = hash:/etc/postfix/virtual

And the /etc/postfix/virtual change:

root@uberserver.home    my-email-addr+root@gmail.com
root@mail.my-registered-domain.net    my-email-addr+rootmah@gmail.com
root@my-registered-domain.net my-email-addr+rootah@gmail.com

(I did this so that I could see different gmail recipients depending on the recipient postfix originally saw.)

Note that I also had to run postmap... then I re-ran the test.

Here's an example of the test email received in gmail:

Bcc: my-email-addr+root@gmail.com
Return-Path: <my-email-addr@gmail.com>
Received: from uberserver.home (pool-xxx-xx-xxx-xx.someplace.fios.verizon.net. [xxx.xx.xxx.xx])
        by smtp.gmail.com with ESMTPSA id v78sm25438329qge.25.2016.
        for <my-email-addr+root@gmail.com>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Sat, 09 Jan 2016 09:00:25 -0800 (PST)
From: Scott Hamilton <my-email-addr@gmail.com>
X-Google-Original-From: scott@uberserver.home (Scott Hamilton)
Received: by uberserver.home (Postfix, from userid 1000)
    id A47B44809C5; Sat,  9 Jan 2016 12:01:02 -0500 (EST)
Subject: test message
To: <root@uberserver.home>
X-Mailer: mail (GNU Mailutils 2.99.98)
Message-Id: <20160109170102.A47B44809C5@uberserver.home>
Date: Sat,  9 Jan 2016 12:01:02 -0500 (EST)


The method you describe is merely used for aliasing non existing mailboxes, I do not know if this behavior can be tweaked to do it differently.
However you can accomplish what you want by editing /etc/postfix/main.cf and adding two lines:

virtual_alias_domains = mydomain.com myanotherdomain.com
virtual_alias_maps = hash:/etc/postfix/virtual

then edit (or create) /etc/postfix/virtual and add:

contact@mydomain.com myself@gmail.com

after saving execute the command sudo service postfix reload

(See also: here)

  • Thanks - and thanks for the link as it informed me of the need to run postmap as an additional step. I updated my original post with more details as this is still not quite functioning how I'd like. I also thought maybe I needed to remove the /etc/aliases and root/.forward attempts I had made but these made no difference when I removed them and restarted postfix (and ran newaliases). – Scott Jan 9 '16 at 17:18
  • You're welcome. When a solution provides you with a correct answer you can confirm this by clicked the accept button so others can quickly see the answer worked for the questioner. see also: askubuntu.com/help/someone-answers – Requist Jan 9 '16 at 17:31
  • Well, it's not quite resolved/answered yet. :) I'm still trying to get the emails set without the BCC directly to the gmail account. – Scott Jan 9 '16 at 20:49

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.