Saturday, 1 October 2011

Debian Server To Send Email Automatically

I run a debian server with Rimu Hosting (highly recommended). Every week I've been going on to do a bit of house keeping. I realised that I could automate those tasks and get the server to send me an email to tell me what it had done. I decided the first problem to solve was to get the server to send me an email from the command line. After a little googling I tried this:

echo "This is a test" | mail -s "Just testing from the server"

That didn't quite work as expected. The problem was that I run my email from Google Apps on my domain. I wanted addresses to be picked up by Google's email servers. However, the debain server knew that it was so decided to handle the email itself. It very efficiently delivered the email to the linux user account on the server, and not my Google mail box.

I needed a way to tell the server that email to should be handed off to Google and not processed locally. A bit more googling led me to the Debian Wiki page about Gmail and Exim4. I followed those instructions to the letter and tried again:

echo "This is a test" | mail -v -s "Just testing from the server"

Nothing seemed to happen at all. No email arrived either locally on the server or to Google. Hmmm.

Back to the drawing board. I next tried to send an email to my wife's account to see if I could figure out what was working.

echo "This is a test" | mail -v -s "Just testing from the server"

That worked like a dream. So the Exim config is working fine, but the mail program doesn't know to go to the SMTP server rather than delivering locally.

Digging into the docs I figured out that I needed to make sure that the "local_domains" parameter was set correctly. I edited /etc/exim4/conf.d/main/01_exim4-config_listmacrosdefs and changed the local_domains parameter to be empty. I re-ran:

sudo update-exim4.conf

...and tried again. It worked. Yeah!

No comments: