Linux send email from console

by Vivek Gite on February 16, 2006 · 14 comments

To send an email from console you need to use mail command, which is an intelligent mail processing system which has a command syntax reminiscent of ed with lines replaced by messages. To send an email to somewhere@domain.com you need to type following command:

$ mail somewhere@domain.comOutput:

Subject: Hello
Hai,
How are you? Hope so you are fine :)
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 then use following command:
$ mail -s 'Hai' somewhere@domain.com < /tmp/messagePlease note that above command will NOT route an email if you do not have properly configured MTA/mail server.

See also:

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

{ 14 comments… read them below or add one }

1 Ahmad March 3, 2008

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

Reply

2 syed nusrath mateen May 28, 2008

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

Reply

3 syed nusrath mateen May 28, 2008

Hi,

How to configure MTA/mail server ?
Please clarify ?

Thanks
Syed Mateen.

Reply

4 Mahantesh December 10, 2008

Hi ,
I tried ,it worked .

How to attach the files ..?

Thanks and Regards
Mahantesh

Reply

5 anil February 19, 2009

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

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

Reply

6 Iceman May 5, 2009

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

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

Reply

7 Brahim May 13, 2009

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.

Reply

8 Renato July 3, 2009

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.

Reply

9 fsckr July 28, 2009

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.

Reply

10 harish February 3, 2010

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

Reply

11 matthew March 3, 2010

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

Reply

12 Iceman March 3, 2010

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

Reply

13 1000hz April 13, 2010

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

Reply

14 sathya April 19, 2011

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

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 9 + 3 ?
Please leave these two fields as-is:
Solve the simple math so we know that you are a human and not a bot.



Previous post:

Next post: