Use Gmail for just outgoing email and replies

For my own privacy, I avoid using free mail services like Gmail and instead run my own mail server (hosted at Brightbox, a very trustworthy cloud server provider here in the UK ;). I do use one or two other Google services which means I have a Google account which means I do actually have a Gmail address. I also have an Android phone and that has the Gmail app preinstalled… by this point you can surely see that I should give up any pretense of privacy, but I prefer clinging onto it’s remaining delicate threads. It provides an illusion of dignity otherwise missing from the Internet.

Anyway, so I happen to have a pretty convenient email account available to me when I’m mobile whether I want it or not. I don’t want to connect it to my own IMAP server, but I don’t want to start sending mail from a Gmail address as it will end up in people’s address books and they’ll start sending new mail there instead.

So I’ve found a compromise: I’ve configured my Gmail account to let me send email from my personal email address (and set up the associated SPF DNS records too). And I’ve configured by own mail server to forward back any *replies* to my Gmail address. So whilst I’m out and about, I can *send emails using Gmail if I need to and read any replies to that email*. But new email direct to my personal address is never seen by Google.

I use maildrop, so my filtering rules are in the mailfilter language:


if ( ( /^In-Reply-To: .*mail.gmail.com/ || /^References: .*mail.gmail.com/ ) && hasaddr("john@johnleach.co.uk") )
{
cc "!mygmailaddress+reply@gmail.com"
}

Any emails that are replies to Gmail emails and are to (or cc) my personal email, get forwarded on to Gmail (to an alias I can use to avoid any forwarding loops).

I could also check the Message-ID header for gmail.com to detect new incoming email that had originated from a Gmail account anyway – the logic there is that Google have already seen it, so my privacy has already been invaded; I may as well get something out of the bargain. Worth noting that replies to my replies to incoming email from Gmail will hit my reply forwarding rule anyway.

Redirecting outgoing mail with Postfix

We have a various staging deployments of our systems at Brightbox and need to test that the emails they send are correct. We have a bunch of test accounts registered with various email addresses and we wanted them all to go to our dev team, rather than the original recipient.

Rather than write support for this into our apps, we used Postfix to redirect the mail to our devs.

In our case, our staging deployments use a local installation of Postfix and the systems are generally not used by anything else, which makes this dead easy.

Firstly, write a rewrite map file, with the following one line of content. Call it /etc/postfix/recipient_canonical_map:

/./ devteam@example.com 

Then configure Postfix like this (in /etc/postfix/main.cf):

 recipient_canonical_classes = envelope_recipient recipient_canonical_maps = regexp:/etc/postfix/recipient_canonical_map 

Now all mail going through this relay will be redirected to devteam@example.com. It rewrites only the envelope, so the important headers are not changed.