The best way I found was using a package called mailx. In ubuntu simply do the following:
sudo apt-get install heirloom-mailx
Next we need to make sure that the user that wants to send the mail has the correct configuration. So in the the user’s home directory, create a file called ~/.mailrc
The contents of the file should look something like the following:
set smtp=smtp://mail.domain.co.za set from="email@example.com (Sender Name)" set smtp-auth=login set firstname.lastname@example.org set smtp-auth-password=yourpassword
There you have it. To send a mail, use the following:
mailx -s 'Hello World' email@example.com < msg
For more information there’s always the man pages.