Please feel free to email me with any questions at with "blog" as the subject.

Search my blog:

Loading...

Friday, 10 September 2010

Set up sendmail in arch linux

I recently had the need to have my backup script send me an email with the backup logfile when it was done.

Here is how I did it (with much help from others)

First you need to install mailx.

The package: mailx-heirloom seems to work better for some people so I used it instead.

bash$ Sudo pacman -S mailx-heirloom

I then set up the config file:

bash$ sudo vim /etc/nail.rc
bash$ sudo vim /etc/mail.rc
(Updated as the config file changed.)
and put the following into it:

set sendmail="/usr/bin/mailx"
set smtp=smtp.gmail.com:587
set smtp-use-starttls
set ssl-verify=ignore
set ssl-auth=login
set smtp-auth-user=login@host
set smtp-auth-password=PASSWORD


Obviously this is for gmail. You may have to modify this for other mail hosts. I tried a few others but gmail was the only one that gave consistant posative results.

You can then send email with the following:

bash$ echo "message" | mailx -s [subject] -a /path/to/attachement recipient@host


My script uses rsync for backups. Here is what I came up with:

#!/bin/bash
DATE=`date +%m-%d-%y`
echo -n "What directory do you want to back up? : "
read DIRECTORY
rsync -avzuh Targetmachine:~/$DIRECTORY . > /home/username/logs/backup-log-$DIRECTORY-$DATE.txt &&
echo "Backup of $DIRECTORY Complete, Log attached" | mailx -s "Backup Complete" -a "/home/username/logs/backup-log-$DIRECTORY-$DATE.txt" user@HOST


It is only made to backup one directory at a time but that is all I currently need. I'm sure more experienced users could modify this and intergrate it as a cron job with passwordless ssh which is what I will be doing when I get my 4 1TB HDD's..