Send Mail From the Command LineIf you use a Linux system, you probably already know about the Terminal and the power provided to you from the command line. If you use the command line, did you know that you can use the command line to send email?

Sure, you can use such clients as Gmail, Yahoo Mail or Hotmail to send and receive email but what if you want to send email for a cron job or send a quick email to test your email client? How would you do it?

Use sendmail to send email from the command line. On many Linux distributions such as Ubuntu, you can install sendmail by using the apt-get command. To run sendmail, type

$ /usr/bin/sendmail
enter body of message

From the command line, run the sendmail, provide the recipient email address, and press <enter>. Afterwards, enter the body of your message. End the message by pressing the Ctrl and D keys.

The above message works but it doesn”t include the Subject line. What if you also want to change the From line? For example, create a text file called mail.txt with the following information:

subject: your-subject

Body of message goes here

To send the message, run the command below:

$ /usr/sbin/sendmail < mail.txt

Leave a Comment