February 5th 2016
My server is running debian stable.
Recently I had been messing around with different mailing setups, which resulted in total breakage of email sending, as often required by a CMS, usually via
Remove unneeded stuff
I was playing with dovecot and exim4 before I realised that what I really want is sSMTP.
I purged all packages that contain 'dovecot' and 'exim4' in their names, and always
performed an "apt-get --purge autoremove" afterwards. Then I went through all
leftover configuration & modifications in /etc and removed them manually.
There was a lot of it, even after purging the packages.
But it seems that even after that some residual configuration files are interfering.
aptitude search ~c will show what is leftover (I should probably have started with that).
aptitude -s purge ~c will simulate the removal, and this:
aptitude purge ~c will finally do it.
If you don't want to use aptitude:
dpkg -l | grep ^rc to see what residual config files are left over and
for i in $(dpkg -l | grep ^rc | cut -d” ” -f3); do dpkg –purge $i; done
With a hopefully clean system, install ssmtp and mailutils:
apt-get install ssmtp mailutils.
Configuration for Gmail:
- activate 'allow less secure apps' from your gmail profile
/etc/ssmtp/ssmtp.confshould look like this:
email@example.com mailhub=smtp.gmail.com:587 rewriteDomain=nn.nn.nn.nn (my IP) hostname=nn.nn.nn.nn FromLineOverride=YES UseTLS=YES UseSTARTTLS=YES AuthUserfirstname.lastname@example.org AuthPass=verysecret AuthMethod=LOGIN
Configuration for picky email provider:
Fix permissions on /etc/ssmtp/ssmtp.conf etc. as outlined here (also for /etc/ssmtp/revaliases, see below).
But that only enabled me to send mail with the same "From" address as is my account's. It's a specialty of picky email provider, i guess. to make it work with my website's email form, i additionally had to:
set up both rewriting in /etc/ssmtp/ssmtp.conf and /etc/ssmtp/revaliases both for root and normal user:
# /etc/ssmtp/ssmtp.conf: email@example.com firstname.lastname@example.org # /etc/ssmtp/revaliases: root:email@example.com:smtp.somemailbox.org:465 username:firstname.lastname@example.org:smtp.somemailbox.org:465
- disallow users to set their own from address in /etc/ssmtp/ssmtp.conf:
Send a test mail:
# ssmtp email@example.com
You will most likely need to be root for this.
sSMTP will then wait for you to type your message, which needs to be formatted like this:
To: firstname.lastname@example.org From: email@example.com Subject: test email hello world!
Note the blank like after the subject, everything after this line is the body of the email. When you’re finished, press Ctrl-D. sSMTP may take a few seconds to send the message before closing.