RSS Feed

How to send email from the command line

A quick and easy test to make sure SMTP is working on a server is to send an email, without a desktop environment this can be done via the command line. This how to demonstrates how to do so on Ubuntu.

First, make sure you have mailutils installed, otherwise you will not be able to use the mail command.

sudo apt-get install mailutils

Once installed the basic syntax is:

mail -s “Subject” < message.txt

Where the -s parameter signifies the subject and then you direct the contents of message.txt into the email.

However, usually when testing SMTP you don’t particularly want to have to create a file with the test message in. If this is the case you can always echo the message and pipe it through to the mail command, like so:

echo ‘This is a test email’ | mail -s “Subject”

Yes, it is that simple.

Posted in Linux on the 10th November 2010

3 people have spoken their minds!

  1. IByDev says:

    Useful, very useful. Thanks srcnix.

  2. Simon Green says:

    Now add an attachment :D


Your email address will not be published. Required fields are marked *