The ssmtp
program is a small ''SMTP'' server that only forwards a system email to an existing mail box on an existing server.
That program is ideal when you'd like to be able to send mail, without having to install or configure the sendmail
Slackware package (which can be a massive pain in the neck, let's face it).
So: how to install ssmtp
?
Download ssmtp
from its home page: http://packages.debian.org/source/sid/ssmtp
Make sure you download the ''orig'' package, and not the Debian one!
Now if you try to compile the program right away, you will probably end up with the following error:
gil:~$ ./configure --enable-logfile --enable-ssl --enable-md5auth ; make all ; sudo make install [...] gcc -o ssmtp ssmtp.o arpadate.o base64.o xgethostname.o md5auth/md5c.o md5auth/hmac_md5.o -lnsl \ -lssl -DSTDC_HEADERS=1 -DHAVE_LIMITS_H=1 -DHAVE_STRINGS_H=1 -DHAVE_SYSLOG_H=1 -DHAVE_UNISTD_H=1 -DHAVE_LIBNSL=1 -DRETSIGTYPE=void -DHAVE_VPRINTF=1 -DHAVE_GETHOSTNAME=1 -DHAVE_SOCKET=1 \ -DHAVE_STRDUP=1 -DHAVE_STRSTR=1 -DLOGFILE=1 -DREWRITE_DOMAIN=1 -DHAVE_SSL=1 -DMD5AUTH=1 -DSSMTPCONFDIR=\ "/usr/local/etc/ssmtp\" -DCONFIGURATION_FILE=\"/usr/local/etc/ssmtp/ssmtp.conf\" -DREVALIASES_FILE=\ \ "/usr/local/etc/ssmtp/revaliases\" -g -O2 -Wall /usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../x86_64-slackware-linux/bin/ld: ssmtp.o: undefined reference to symbol 'X509_free' /usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../x86_64-slackware-linux/bin/ld: note: 'X509_free' is defined \ in DSO /lib64/libcrypto.so.1 so try adding it to the linker command line /lib64/libcrypto.so.1: could not read symbols: Invalid operation collect2: error: ld returned 1 exit status make: *** [ssmtp] Error 1
Here is the proper procedure to compile it:
First run the configure command as follows:
gil:~$ ./configure --enable-logfile --enable-ssl --enable-md5auth
Next, edit the Makefile
and replace:
$(CC) -o ssmtp $(OBJS) -lnsl -lssl $(CFLAGS)
With the following:
$(CC) -o ssmtp $(OBJS) -lnsl -lssl -lcrypto $(CFLAGS)
Now, run the usual:
gil:~$ make ; sudo make install-sendmail
(Please note the install-sendmail directive)
And you are done!
The program ssmtp
on its own is not very useful. Let's make it send system emails to a Google Mail account.
First, let's make some symbolic link to make sure ssmtp
replaces sendmail
on our machine:
root:~# ln -s --verbose /usr/local/sbin/ssmtp /usr/bin/sendmail '/usr/bin/sendmail' -> '/usr/local/sbin/ssmtp' root:~# ln -s --verbose /usr/local/sbin/ssmtp /usr/sbin/sendmail '/usr/sbin/sendmail' -> '/usr/local/sbin/ssmtp' root:~# ln -v -s /usr/local/etc/ssmtp/ /etc/ssmtp '/etc/ssmtp' -> '/usr/local/etc/ssmtp/'
Oh, look, there is a sendmail
installed now!
root:~# which sendmail /usr/local/sbin/sendmail root:~# ll $(which sendmail) lrwxrwxrwx 1 root root 5 Jan 10 14:48 /usr/local/sbin/sendmail -> ssmtp*
Good, now edit /etc/ssmtp/ssmtp.conf
and put the following in:
# # /etc/ssmtp.conf -- a config file for sSMTP sendmail. # # The person who gets all mail for userids < 1000 # Make this empty to disable rewriting. root=your_name_here@gmail.com # The place where the mail goes. The actual machine name is required # no MX records are consulted. Commonly mailhosts are named mail.domain.com # The example will fit if you are in domain.com and you mailhub is so named. mailhub=smtp.gmail.com:587 # Where will the mail seem to come from? rewriteDomain= # The full hostname hostname=your_name_here@gmail.com # -------------------------------------------------------- # Authentication # -------------------------------------------------------- UseTLS=YES UseSTARTTLS=YES AuthUser=your_name_here AuthPass=your_password_here AuthMethod=LOGIN FromLineOverride=YES # -------------------------------------------------------- # Ref. : http://www.nixtutor.com/linux/send-mail-with-gmail-and-ssmtp/ # https://wiki.debian.org/sSMTP # --------------------------------------------------------
Add this to the /etc/ssmtp/revaliases
file:
# sSMTP aliases # # Format: local_account:outgoing_address:mailhub # # Example: root:your_login@your.domain:mailhub.your.domain[:port] # where [:port] is an optional port number that defaults to 25. root:your_name_here@gmail.com:smtp.gmail.com:587 gil:your_name_here@gmail.com:smtp.gmail.com:587
Send yourself a mail... And you should be in business!
For instance, if you entered the connection information correctly, the following command should work:
gil:~$ echo "This is a test message from: $(hostname)." | mailx -s "[TEST] $(uname -n) $(date)" your_name_here@gmail.com
Pat yourself on the back: your system can now send email through Gmail! Cool!