exim4 and multiple GMail accounts

Split-routing based on sender address in exim4

mutt is my preferred client for reading and writing mails. And I do have multiple accounts, some on my private server some on GMail (private as well as business).

Initial setup was using my private mail server as single smart host for relaying all outgoing emails. That is sub-optimal as things like DKIM and SPF are basically not working and your GMail emails looks like not legitimate.

which instructs mutt to use From address as the from at email’s envelope as well. Other lines are setting default From addresses. Making sure, that if I am at work, I will send email from my work address as well.

exim4

I am on Debian GNU/Linux so exim4 is the default MTA. I do use postfix on servers, but exim4 is quite flexible in configuration and works well on laptop. I am using config split into multiple files (current Debian default approach).

Following changes will route exceptions, in my case emails via GMail. I will keep my previous (standard) configuration for using a smarthost.

To be able to split route emails, we need to into

router (== what to send)

transport (== where to send)

authenticator (== how to prove eligibility to send)

router

Following code takes care of selecting emails which will need special treatment:

Which is in /etc/exim4/conf.d/transport/30_exim4-config_remote_smtp_gmail.

authenticator

Authentication turned to be the hardest part of the setup. exim4 allows only one autheticator per protocol (called public_name). You can add conditions via client_condition, but the limitation on one authenticator per public_name will still hold. Conditions are used as a last resort for disabling certain mechanism if you don’t like for example used encryption method. So I have ended up with this

There is a bit of redundancy, which could have been removed. But I have decided to stick with the default format to have only one file with password.

Final words

Hope this will help somebody to keep using awesome commandline environment for managing loads of email. I would also suggest double-checking that your exim is listening on localhost only. So it is not reachable over network: