The purpose of this document is show you how to send email form Ubuntu with Gmail. There is a package designed just for this mission: ssmtp. So, if you want to send mail from your Ubuntu desktop, It is a good choise. Let`s just install ssmtp.
NOTE Before you complete the following steps, need to delete Postfix/sendmail packages.
$sudo apt-get install ssmtp mailutils
Then edit the ssmtp configuration file:
$sudo vim /etc/ssmtp/ssmtp.conf
Comment out the “root” , “hostname” and “mailhub” lines. Add the following a the end of this file:
email@example.com mailhub=smtp.gmail.com:587 rewriteDomain=gmail.com hostname=<YOUR MACHINE HOSTNAME> AuthUser=your_gmail_username # firstname.lastname@example.org AuthPass=your_gmail_password FromLineOverride=Yes UseTLS=Yes UseSTARTTLS=Yes
Configure SSMTP “/etc/ssmtp/revaliases” file to looks like:
Then, save the change. Add the “heirloom-mailx” as mail application in command line.
$sudo apt-get install heirloom-mailx
Now you can also use mail from the command line with something like:
$echo "test text" | mail -s "test mail content" email@example.com
The text “test text” is sent to the email address firstname.lastname@example.org (you may also specify multiple addresses separated by spaces) with the subject “test mail content”. For more options type mail –help.