Email configuration and Linux mail commands

Being able to send emails from command-line from a server is quite useful when you need to generate emails programatically from shell scripts or web applications for example.

Steps to follow

For Video Reference

Tamil Version :
English Version :

Run the bellow command to install the mail utils .

sudo apt-get install mailutils

Open the bellow file and fill the following details 

sudo vi /etc/postfix/

relayhost = []:587

smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl/sasl_passwd
smtp_tls_security_level = encrypt
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt4

Now save the file and Reload it 
sudo postfix reload

Create a new file named as sasl_passwd  and save the file

sudo vi /etc/postfix/sasl/sasl_passwd

Run the following command to map the password 
sudo postmap /etc/postfix/sasl/sasl_passwd

Run the following command to send mail 

echo “test alert” | mail -s “system down”

Now Check the mail


For debugging use the following command
tail -f /var/log/mail.log

Leave a Comment