SMTP mail for ubuntu.

Hi I am nik. I have just done with the- “How to mail from terminal and crontabs on ubuntu using the SMTP server.” It was too easy to do this, so lets see how to send mails using smtp server and trust me it will take just few minutes .

First of all we need to install the ssmtp by running following command in terminal:

sudo apt-get install ssmtp

Now open the ssmtp configuration file with:

sudo nano /etc/ssmtp/ssmtp.conf

and edit the file with following lines in it:

above example is with gmail. If you’re not using gmail you have to change the mailhub and root lines. For yahoo mail change the mailhub line to

Now go and edit sSMTP aliases by typing this command

sudo nano /etc/ssmtp/revaliases

and write following lines in that file:

Now we are ready to send mail from our terminal, for this just type the following command in terminal:

echo "Test message" | mail -s "Test subject"

now check the receivers mail inbox you will find your mail there in few seconds.

When if you want to do this using crontabs just write above command with appropriate schedule that you want.

Also we can send the attachments file with mail by simply adding the path of the file as given bellow the example , having crontab wishing to mail in every five minutes with the attachment file:

*/5 * * * * echo "Test message" | mail -s "Test subject" < path/where/the/attachments/file.etc

Hope this will helpful to all those who stuck in the smtp auto mailing.

If your still facing problems go to your gmail accounts setting and turn on the Access for less secure apps.

now you’r able to send mails from the terminal and using crontabs.

Don’t forget to give your valuable suggestions.

Thank you for reading.