How to send email on Linux (CentOS 6.4)

There are two ways:
1.mailing contents of a file, the format of the command is:
mail -s “title” destination_email < file
It’s best to illustrate with an example, let’s say you have a file shopping.txt with the following content:

eggs
milk
bacon 

you use the command:
mail -s “Shopping List” youremailaddress@gmail.com  < shopping.txt
when you log onto your email, you should see the following message with the title “Shopping List” (most likely in your spam folder):

eggs
milk
bacon

2. mail using echo and pipe:

Let’s say you just want to type the contents of the email on the command line instead of saving it into a file, then you’ll have to use echo and  pipe.  Echo outputs the text given and pipe basically takes the output of a command as the input of another command, we’ll get into details of this later.
The format of the command is:
echo “contents” | mail -s “title” destination_email
example:
echo “eggs milk bacon” | mail -s “Shopping List” youremail@gmail.com
you should receive an email “Shopping List” with the content:

eggs milk bacon

Advertisements
This entry was posted in Linux Tips. Bookmark the permalink.

One Response to How to send email on Linux (CentOS 6.4)

  1. Anonymous says:

    nice example, thanks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s