Sending mail from terminal in Linux using SMTP server

posted in: Linux | 0

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="user@domain.co.za (Sender Name)"
set smtp-auth=login set smtp-auth-user=smtp@domain.co.za
set smtp-auth-password=yourpassword 

There you have it. To send a mail, use the following:

 mailx -s 'Hello World' user@domain.co.za < msg 

For more information there’s always the man pages.

Leave a Reply