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="firstname.lastname@example.org (Sender Name)" set smtp-auth=login set email@example.com set smtp-auth-password=yourpassword
There you have it. To send a mail, use the following:
mailx -s 'Hello World' firstname.lastname@example.org < msg
For more information there’s always the man pages.