Tran Nghi's Site  - Make notes and share experience

Configure Linux Server (Ubuntu 16.04 LTS) to send email…

This post is also available in: Vietnamese

Setup and Configure SSMTP and MAILUTILS to send email from system, ie: alarm notification, crontab’s message…
This tools is useful that you do not need to setup a MTA (Mail Transfer Agent) like SMTP Server, Sendmail… to deliver system’s message.

[email protected]:~# sudo apt install ssmtp mailutils

[email protected]:~# cat /etc/ssmtp/ssmtp.conf
#--------------------------------------
#
# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
root=<ie: [email protected]>

# 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=mail
mailhub=<your email's servcer:port>
AuthUser=<your email's account>
AuthPass=<your email's password>
UseTLS=YES
UseSTARTTLS=YES

# Where will the mail seem to come from?
rewriteDomain=<ie: infotechviet.com>

# The full hostname
hostname=<ie: infotechviet.com>

# 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
#--------------------------------------

Test sending an email:

[email protected]:~# echo "Hello, this is mail content for test" | mail -s "Hello test!!!" "[email protected]"

Tips:

Configure alias for root, or postmaster to forward system’s message to your expect email address.

[email protected]:~# vi /etc/ssmtp/revaliases
#----------------------------------------
#
# sSMTP aliases
# 
# Format:       local_account:outgoing_address:mailhub
#
# Example: root:[email protected]:mailhub.your.domain[:port]
# where [:port] is an optional port number that defaults to 25.
root:[email protected]
romano:[email protected]
postmaster:[email protected]
#
#----------------------------------------
[email protected]:~#
Message