Linux Send Email From Console

How do I send an email using command line under Linux?

To send an email from console you need to use the mail command. It is an intelligent mail processing system which has a command syntax reminiscent of ed with lines replaced by messages. To send an email to [email protected] you need to type the following command:

$ mail [email protected]
Sample outputs:

Subject: Hello
Hai,

How are you? 

Take care,

Babai

Vivek
. <Type  DOT (.) followed by ENTER KEY>
Cc: <Press ENTER KEY>

You need to type . (dot) to send an email. To send contains of file (such as /tmp/message) as mail body, use the following syntax:
$ mail -s 'Hai' [email protected] < /tmp/message

Please note that above command will NOT route an email if you do not have properly configured MTA/email/ISP server that accepts forwarding from your shell account. You can also use gmail account to forward email (i.e. relay email) as described here.

See also:

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.