Sendmail Using Nullmailer and a Gmail Account on a Linux Server
Join the DZone community and get the full member experience.Join For Free
When you run VPS servers or other “low end” boxes it is common scenario need to setup a outgoing email mail transfer agent to get reports from cron jobs or enable PHP scripts to send email.
Linux offers some really heavy weight options for sending email, including Sendmail, Postfixand Exim4. However, if you are a low end box user, you run low end services of which requirements are likely to send one email per month from your puny cron job or web contact form. This makes the options above
- Plain scary
- Very difficult to configure, maintain, due to extra complexity not necessary for your use case
- Open some attack surface
- You still need a master SMTP where you push forward your email messages
They don’t scale down.
But that’s not all. If you are using low end boxes you probably don’t need good SMTP service from your VPS provider (spam makes them expensive to provide). So, here is the trick: you are probably using already a free web email provider like gmail, Hotmail or whatever happens to be the dominating internet company of the day. Nullmailer can be configured to use authenticated SMTP sending through any email provider quite easily.
Below is a setup script for Ubuntu / Debian (tested on Ubuntu 12.04 LTS) which setupsxinetd tunnel to connect to GMail’s smtp.google.com and send emails as your authenticated Gmail user. The orignal idea is described in this blog post by Jon Spriggs.
The downside of this hacky solution include
- No real email From addresses: all email is aliased to your authentcated SMTP user
- SMTP user password is stored on the server as plain text, so you probably want to create a rogue gmail user for this
- No locally buffered email (not sure about this with Nullmailer?) – if SMTP acts strangely be prepared for major screw up
- Using sendmail command with this solution may cause delays and other issues in the script (not sure how timeouting is handled with Nullmailer?)
Nothing else is needed, except running the script as instructed.
Published at DZone with permission of Mikko Ohtamaa, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.