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” alias@domain.com < 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” alias@domain.com

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

SPEAK YOUR MIND...

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

*