0 like 0 dislike
585 views
asked Aug 31, 2013 in Computers & Internet by VN (230 points) | 585 views
    

1 Answer

0 like 0 dislike
Best answer

The Linux command line can be very powerful once you know how to use it. You can parse data, monitor processes, and do a lot of other useful and cool things using it. There often comes a need to generate a report and mail it out. It could be as simple a requirement as a notification that the day’s backup went through fine, or did not. I’ll help you get started with sending mails from the Linux command line and in shell scripts. We will also cover sending attachments from the command line. We will begin with the “mail” command.
MAIL

First run a quick test to make sure the “sendmail” application is installed and working correctly. Execute the following command, replacing “you@youremailid.com” with your e-mail address.

If this doesn't work means you do not have sendmail installed on your centos(linux) the install the same from the following command "yum install sendmail" & after installing just start the sendmail service by the command "service sendmail start"

After starting successfully you will get this on screen

Starting sendmail:                                         [  OK  ]
Starting sm-client:                                        [  OK  ]


# mail -s “Hello world” you@findoutanswer.com

Hit the return key and you will come to a new line. Enter the text “This is a test from my server”. Follow up the text by hitting the return key again. Then hit the key combination of Control+D to continue. The command prompt will ask you if you want to mark a copy of the mail to any other address, hit Control+D again. Check your mailbox. This command will send out a mail to the email id mentioned with the subject, “Hello world”.

To add content to the body of the mail while running the command you can use the following options. If you want to add text on your own:

# echo “This will go into the body of the mail.” | mail -s “Hello world” you@findoutanswer.com

And if you want mail to read the content from a file:

# mail -s “Hello world” you@findoutanswer.com < /home/calvin/application.log

Some other useful options in the mail command are:

-s subject (The subject of the mail)
-c email-address (Mark a copy to this “email-address”, or CC)
-b email-address (Mark a blind carbon copy to this “email-address”, or BCC)

Here’s how you might use these options:

# echo “Welcome to the world of FOA” | mail -s “Hello world” foa@abc.com -c foa2@abc.com -b foa3@abc.com

answered Aug 31, 2013 by VN (230 points)
edited Aug 31, 2013 by VN

Related questions

0 like 0 dislike
1 answer
1 like 0 dislike
2 answers
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
1 like 0 dislike
1 answer
1 like 0 dislike
1 answer
0 like 0 dislike
1 answer

Where your donation goes
Technology: We will utilize your donation for development, server maintenance and bandwidth management, etc for our site.

Employee and Projects: We have only 15 employees. They are involved in a wide sort of project works. Your valuable donation will definitely boost their work efficiency.

How can I earn points?
Awarded a Best Answer 10 points
Answer questions 10 points
Asking Question -20 points

Mathe Forum Schule und Studenten
1,164 questions
1,304 answers
275 comments
1,589 users