How to send mail from linux command prompt

How to send mail from linux command prompt

Question: How to send mail from linux command prompt and how to add a attachment in the mail.

Answer: To send a mail from linux command prompt we can use mail or mutt command. To send a mail with attachment use mutt command from linux command prompt

 

How to send mail from linux command prompt
In this post i am going to explain you how to send mail from linux command prompt and how to send a mail with attachment. Make sure you have installed sendmail and dovecot in your machine and its working properly.

How to send mail from linux command prompt

mail:

Using mail command we can send mail from command prompt itself. Let’s see how to do that with examples.

Options:

-s – Used to specify the subject,
-c – Used to send carbon copies or cc,
-v – Verbose it will show how mail sends

First Method to send mail from linux command prompt

The “Test mail” is the body of the mail
echo “Test mail” | mail -s “subject” raj@gmail.com

Second Method to send mail from linux command prompt

Output of ls command may send as the body of the mail
ls | mail -s “subject” raj@gmail.com

Third Method to send mail from linux command prompt

mail -s “this is the subject” raj@gmail.com    —–> Then press enter
This is the body of the mail                             —–> Then press enter
.                                                                       —–> Hit Full stop to say end and
enter. Then add cc if you want

mutt:

Mutt command is used to send mail from command prompt. Using mutt command it is easy to add an attachment in the mail

Options:

-s – Used to specify the subject,
-c – Used to send carbon copies,
-v – Verbose it will show how mail sends,
-a – Used to attach a file.

First Method to attach a file and send from command prompt

Attach the file s.zip and mail body from c.txt file
mutt -s “I am the subject” -a s.zip raj@gmail.com < c.txt

Second Method to attach a file and send from command prompt

Gets body of the mail from the standard output of echo command
echo “I am the body of the mail’ | mutt -s “subject of mail” -a attach.txt raj@gmail.com

Third Method to attach a file and send from command prompt

echo “I am the content of the mail” mutt -s “subject of mail” -a attach.txt raj@gmail.com -c dhana@gmail.com

The above example explains you how to send a mail with cc




2 thoughts on “How to send mail from linux command prompt

  1. Praveen Reddy.M

    Install the package
    #yum install sendmail* -y
    #rpm -qa | grep sendmail (to check the package are installed or not)

    #vim /etc/mail/sendmail.me (Open the config file)
    Go to Line no 116 add like
    dnl # deamon options
    :wq

    #service sendmail restart
    #chkconfig sendmail on
    now send an email

    #mail -s “hiii” username@servername.com (enter)
    write the massage then ctrl+d to save and finish massage
    again it ask the CC address if require enter cc address if no just enter
    then the mail ill sent to that what u mentioned address

    Reply

Leave a Reply

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