Use Gmail as a Smart Host

Posted by Ceri Davies Fri, 09 Sep 2005 21:36:00 GMT

I like to send mail direct from my home network for various reasons, not least being that I used to work on my current ISP’s mail servers and I know that they are in and out of blackholes these days like Hawking radiation. By sending mail directly from my dynamic block, the results are at least somewhat consistent.

Some may suggest changing ISP, but I am happy with every other aspect of their service, and there is no guarantee that any other ISP won’t run in to the same problems at any point in the future. Exim makes it easy for me to maintain a list of domains that do require me to use my ISP’s smart host, and even has the decency to read it dynamically, so it’s little hardship for me to: echo painintheass.net >> /usr/local/etc/exim/smarthost.domains for those domains that do need it.

Occasionally, however, I run into problems whereby the recipient that I am trying to mail won’t accept mail from me or the upstream smart host at the ISP. In the past, that has meant that I’ve been stuffed, which would normally be the would-be recipient’s problem, but every so often I really, really want to send them the message.

This just happened twice in the space of ten minutes, so I worked out how to get exim to relay mail via smtp.gmail.com:

  • First, enable POP for your gmail account. You do that in the “Forwarding and POP” section of the settings. Strangely enough.

  • Next, add a domain list to your exim configuration:

    domainlist use_gmail_domains = /usr/local/etc/exim/gmail.domains

    This domain list will hold the list of domains to send via gmail, one domain per line. If you don’t have any to add now, create the file empty with touch(1) so that you don’t forget later. Exim won’t complain either way.

  • Create an authenticator. Note that although we’re using the plaintext mechanism here, we’ll force TLS in the transport so your details will not get transferred in the clear:

    gmail_login:
      driver = plaintext
      public_name = LOGIN
      client_send = : YourGmailUsername@gmail.com : YourGmailPassword

    Note that in a default exim configuration there are usually no authenticators, so don’t forget the begin authenticators statement if this is your first one.

  • Add a router:

    send_via_gmail:
      driver = manualroute
      domains = +use_gmail_domains
      transport = gmail_smtp
      route_list = "* smtp.gmail.com byname"
  • Add a transport, forcing it to use AUTH and TLS:

    gmail_smtp:
      driver = smtp
      hosts = smtp.gmail.com
      hosts_require_auth = smtp.gmail.com
      hosts_require_tls = smtp.gmail.com

That’s all it requires. You may now need to lock down the permissions on your configuration file to stop anyone reading your username and password from it. Advanced exim users can work out how to put this information in a separate file easily enough.

Posted in ,  | 2 comments

Comments

  1. Dick Davies said 11 days later:

    Nice, ta. One thing I'd add is that if you replace

    client_send: user : pass

    in the authenticator with

    hide client_send: user : pass

    you'll be safe from 'exim -bP client_send' snooping. Although I might have that wrong.

  2. Ceri said 11 days later:

    I didn't know about the hide option, thanks.

    In this case, however, it's not required; client_send is an option in the authenticator setting, so exim -bP won't display it any more than exim -bP transport would.

Comments are disabled