How to Send an Email (Mail Message) from Linux Command Line Shell

Occasionally system administrator may need to send a test email, or emergency mail message right from the shell or command line interpreter when using a Linux flavor or distribution of operating system, be Red Hat Fedora, Ubuntu, Debian, CentOS, Open SUSE, FreeBSD and others. In this case, the mail command will come in handy.

mail is a command to send and receive mail in Unix, Linux and BSD operating system. To initiate a mail sending process, just type in the following command:

mail recipient@domain.com

Obviously, replace recipient@domain.com with a valid email address.

The system will prompt for a subject of the email before allowing user to type in the mail message body.

# mail receipent@domain.com
Subject: For Testing Only
This email is for testing the mail delivery system only.
^D (EOT)
Cc:

Once finished typing the email message, press Ctrl-D (shown as ^D in example above), which represents End of Text (EOT). Depending on system, mail may or may not prompt another input request for any recipients to cc (carbon copy) to. Press Enter to skip or accept the input, and get the mail sent.

Tip: If the sender and recipient is on the same system, it’s possible to omit the domain (@domain.com) part of the address, leaving only user name.

It’s also possible to use mail’s arguments or switches to directly send mail without interactive input. For example,

mail -s Test address@domain.com < /dev/null

Command above will immediately send a blank email with empty body to the recipient address with the subject "Test". For more arguments, type "man mail".


3 Responses to “How to Send an Email (Mail Message) from Linux Command Line Shell”

  1. maria a.
    July 29th, 2009 06:48
    3

    how do i config my sendmail to make it work? i have ubuntu and it wont work without it.
    thanks!

  2. tim
    June 29th, 2009 00:24
    2

    you have to config your sendmail to make it work

  3. 908
    June 28th, 2009 11:53
    1

    Argh. It’s a Terminal not a commandline.

Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe to comments feature has been disabled. To receive notification of latest comments posted, subscribe to My Digital Life Comments RSS feed or register to receive new comments in daily email digest.
Custom Search

New Articles

Incoming Search Terms for the Article

sendmail command line - linux mail command - send mail from command line - sendmail command line example - linux mail command line - linux sendmail command - send email from command line - shell mail command - send mail linux - send mail command line - linux mail example - sendmail example command line - linux send mail from command line - linux mail from address - linux sendmail example - send mail command line linux - linux command line email - send mail linux command line - mail linux command - test sendmail command line - sendmail command example - mail command linux - send mail from linux - linux mail command example - sendmail test email - sendmail from command line - sendmail linux example - ubuntu sendmail command line - sendmail commandline - centos send email command line - How to send and receive SMTP mails from the shell in linux - linux send mail command line - send mail from command line linux - sendmail command line subject - sendmail test message - linux send mail - linux mail examples - mail linux example - man mail linux - linux command line mail - Linux mail commandline - command line send mail - linux mail from command - command line sendmail - command to test sendmail - send email from linux command line - sendmail send test message - linux mail commands - +linux+mail+message+body - sendmail shell example -