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:
root=yourusername@gmail.com
mailhub=smtp.gmail.com:587
rewriteDomain=gmail.com
AuthUser=yourusername@gmail.com
AuthPass=yoursecretpassword
FromLineOverride=YES
UseTLS=YES
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 mailhub=smtp.mail.yahoo.com:587
Now go and edit sSMTP aliases by typing this command
sudo nano /etc/ssmtp/revaliases
and write following lines in that file:
root:yourusername@gmail.com:smtp.gmail.com:587
username:yourusername@gmail.com:smtp.gmail.com:587
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" otheruser@gmail.com
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" otheruser@gmail.com < 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.