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 vgite@cyberciti.biz you need to type the following command:

ADVERTISEMENTS

$ mail vgite@cyberciti.biz
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' vgite@cyberciti.biz < /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:

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
19 comments… add one
  • Ahmad Mar 3, 2008 @ 10:37

    Thank you, I tried that command and it warked so fin.

  • syed nusrath mateen May 28, 2008 @ 13:00

    Hi,
    I am not able to send mail using mail utility,
    I used

    mail -s “Subject” somewhere@domain.com

    the moment I am sending mail, its getting bounced to delively failed list. I have tried several attempts, it not working. Do I have to configure some server like pop3 before I go ahead and send mail ?

    Please help in this regard.

    Thanks
    Syed Mateen

    • Bill Nye the Science Guy Nov 6, 2015 @ 23:43

      Many email providers will not accept incoming mail from SMTP, which is what your computer probably uses as the default for the “mail” command. Gmail will, however, accept 50 incoming SMTP messages per day.

      If you want to configure your mail program to use something other than SMTP, then you’ve got a lot of setup ahead of you…

  • syed nusrath mateen May 28, 2008 @ 13:32

    Hi,

    How to configure MTA/mail server ?
    Please clarify ?

    Thanks
    Syed Mateen.

  • Mahantesh Dec 10, 2008 @ 12:26

    Hi ,
    I tried ,it worked .

    How to attach the files ..?

    Thanks and Regards
    Mahantesh

  • anil Feb 19, 2009 @ 3:31

    use mutt client with -a option to send mail with attachement

    e.g mutt -a -s mailid@domainname.com

  • Iceman May 5, 2009 @ 23:04

    Or you could use:
    uuencode FILENAME FILENAMEATTACH | mailx user@domain.com

    FILENAME is the original filename
    FINENAMEATTACH is the “destination” attachment filename

  • Brahim May 13, 2009 @ 12:43

    I used the mail command to send a message to my mailbox as a test and on the console it seems working but when i check my mailbox i see no incoming message.
    Should i configure something so the command works properly?
    Thanks in anticipation.
    Brahim.

  • Renato Jul 3, 2009 @ 17:27

    Hello. Shomeone could help me please, i tried to use the mail command but it does not work
    What must I do ?

    renato@10.12.80.20‘s password:
    [renato@erycia2 ~]$ mail -s ‘hi’ rhernand@erycia.com
    .
    Cc:
    Null message body; hope that’s ok
    [renato@erycia2 ~]$ can not chdir(/var/spool/clientmqueue/): Permission denied
    Program mode requires special privileges, e.g., root or TrustedUser.

  • fsckr Jul 28, 2009 @ 18:26

    In case anyone needs to troubleshoot the interactive command line mail process you can use:
    mail -v -s “Hello Recipient”
    Here is my full message
    .
    Cc:

    The -v is verbose and it outputs the full details of the transaction between the sending and receiving servers.

    @Renato, it seems that your user doesn’t have the correct permissions to access the mail queue. Ask your sysadmin to add you to the group of users that is allowed to send email.

  • harish Feb 3, 2010 @ 13:17

    i have used this mail option and its working

    i tries to reply to that from my mail box.. can some one assist me in replying the mail recieved from the linux box.

    Thanking you in advance
    Harish

  • matthew Mar 3, 2010 @ 15:31

    How do zou attach something to a letter using the mail program?

  • Iceman Mar 3, 2010 @ 21:38

    Have you read my previous message?
    Read and you will know it…

  • 1000hz Apr 13, 2010 @ 13:57

    I am a freshman in Linux,I am going to work hard on it.:-)

  • sathya Apr 19, 2011 @ 10:30

    when i use mail command its not working,I have made canges in the sendmail.cf ,sendmail.mc,resolve.conf,and hosts file too and i have restarted the service.but its not sending mail if i logged into the user ex :autobuild@hostname.domain.com and if i give the mail command its not hittting the id.but its working fr SMTP protocol,connecting it with relay server.then mail from:autobuild@hostname.domain.com RCPT TO:id,it reaches the id.can anyone help me with this process of sending mail using mail command.OS is redhat 5.4

  • Vinay May 9, 2012 @ 4:50

    Cool .. It works. Thanks

  • Bardibul Jun 1, 2012 @ 13:26

    Bonjour à tous!

    Je me suis essayé à envoyer un mail avec la commande “mail xxx.xxx@gmail.com -s test”
    j’ai bien rempli la ligne Cc: puis Subject:
    J’ai ensuite de l’espace pour écrire mon mail mais je n’arrive pas à l’envoyer. Je m’explique, la commande “.” ne me permet pas de retourner sur la console.
    Quelqu’un pourrait m’aider? Merci!

    Bardi

  • BrianBlaze Nov 27, 2012 @ 16:17

    How, or is it possible to send mail with the mail command to a group instead of a user? I have been looking it up and can’t find anything leading me to believe that there is no way :(

  • Ian Sep 14, 2013 @ 13:01

    Hi! How to send an email to all the users from my computer, using a makefile?
    Thanks.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.