How to configure sending mail from Linux – easy way

I have spent some time to configure sendmail on Linux server in order to send mail trough our MS Exchange 2007. All was good, email has been sent but never delivered as the MS Exchange server was refusing to deliver and failed every time. Sendmail is great if you are able to configure it and it works 😉 I spent so much time on Internet, reading man pages and even the book — no go 🙁

. . .

It was  depressing to have so many troubles with such simple task. All has been resolved today. I have found way easier way to do this and it works out of the box with few lines of modifying. It is very simple and fast and you can be up and running under 2 minutes.

I have found this great utility called ssmtp

It works under Debain, Centos, FreeBSD … and it is virtually simple to configure. I have it installed on Debian

su
apt-get install ssmtp

Once installed you will find two conf files under

cd /etc/ssmtp
ls
revaliases ssmtp.conf

I have hosting for domain (MYDOMAIN.COM) with 1and1 and their smtp server is using port 587. I have created email as mailer@mydomain.com and here is how I configured it in the ssmtp.conf file

# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
# root=postmaster
root=mailer@mydomain.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
mailhub=smtp.1and1.com:587

# Where will the mail seem to come from?
rewriteDomain=mydomain.com

# The full hostname
hostname=debian6.localdomain

AuthUser=mailer@mydomain.com
AuthPass=Passw@rd#43
UseSTARTTLS=YES

# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address
#FromLineOverride=YES

Once you have edited the file, save it and try to send email, for example I will try to get listing of directory and send it to me

ls -l | mail -s "DIRECTORY LISTING" roman@mydomain.com

If all went fine you should get your email with the directory listing in few seconds to your email (roman@mydomain.com). That is it, was simple and it works ! You can even easily configure ssmtp to send email via Google smtp server. All works and now I am getting my system emails as expected 😉 Let me know in comments if you have troubles to configure it.

Leave a Reply