Sendmail Linux Examples

Sendmail on the command line:

$ sendmail emailaddress write body of message CTRL-D

The CTRL-D is a end of message code for standard-in.

Example :

From: your-email@example.com

To: email@example.com

enter body of message

 

This message is missing a useful TO:line as well as a subject. To create these you need to create a file or use a script.

   $ vim email.txt

date: todays-date    // not required

to: user-email@example.com

subject: subject

from: your-email@example.com

Body of message goes here

 

Then call sendmail with that file as an input:

    $ sendmail -t user-email@example.com < email.txt

 

Or you can use the -toption to to tell sendmail to read the header of the message to figure out who to send it to.

$ sendmail -t < mail.txt

 

This will process the To: and CC: lines for you and send the mail to the correct addresses.

Or call from a script:

#!/usr/bin/perl

use Time::localtime;

open (OUT,”|/usr/sbin/sendmail -t”);

print OUT “From: your-email\@domain.com\n”; ## don’t forget to escape the @

print(OUT “Date: “.ctime().”\n”);

print(OUT “To: $email\n”);

print(OUT “Subject: $subject\n”);

print(OUT “\n”);

print(OUT “$body\n”);

close(OUT);

About these ads

About govath

My name is Alexadros Theofilou im working as an Linux/Windows Administrator in Cyprus.

16 responses to “Sendmail Linux Examples”

  1. garmin 1490t says :

    I can see you’re an expert at your field! I am launching a internet site soon, and your details will likely be extremely useful for me.. Thanks for all your assist and wishing you all of the success.

  2. research papers says :

    I’m impressed, I must say. Really rarely do I encounter a blog that’s both educative and entertaining, and let me tell you, you have hit the nail on the head. Your idea is outstanding; the issue is something that not enough people are speaking intelligently about. I am very happy that I stumbled across this in my search for something relating to this.

  3. Rayford Muckelvaney says :

    Oh my goodness! an amazing article dude. Thank you However I am experiencing difficulty with ur rss . Don?t know why Unable to subscribe to it. Is there anyone getting similar rss drawback? Anybody who is aware of kindly respond. Thnkx

  4. hq Kite says :

    How did you make a site look this awesome!? Email me if you get the chance and share your wisdom. Id be thankful.

  5. lightwind kitesurfing says :

    Is it okay to insert a portion of this on my personal weblog if perhaps I post a reference point to this web page?

  6. 4 3 1 green poison says :

    Nice article, thank you! I really love it.

  7. Pradeep says :

    how to attach a file in the sendmail command, can i have the simple syntax,
    excatly i’m looking for : sending a logfile.tar to my mail id.

  8. Glenn says :

    Valuable info. Lucky me I found your site accidentally, and I am surprised
    why this twist of fate didn’t took place in advance!
    I bookmarked it.

  9. cheap beats by dre beatbox portable says :

    Hello there! This blog post could not be written much better!
    Reading through this article reminds me of my previous roommate!

    He continually kept preaching about this. I am going to send this post to him.
    Pretty sure he will have a good read. I appreciate you for sharing!

  10. band t-shirt screen printing says :

    Hey there, You have done an incredible job. I’ll certainly digg it and personally
    suggest to my friends. I’m sure they’ll be benefited from this site.

  11. mobile games says :

    Simply wish to say your article is as astonishing. The clarity in your post is just spectacular and i
    can assume you’re an expert on this subject. Well with your
    permission allow me to grab your feed to keep up
    to date with forthcoming post. Thanks a million
    and please carry on the rewarding work.

  12. mobile games says :

    I’m amazed, I have to admit. Rarely do I come across a blog
    that’s both equally educative and engaging, and without a doubt, you have hit the nail on the head.

    The problem is something which too few people are speaking intelligently about.
    I am very happy I came across this in my hunt for something relating
    to this.

  13. best replica rolex datejust ii says :

    Thankfulness to my father who stated to me regarding this website, this website is in fact amazing.

Trackbacks / Pingbacks

  1. free ipad - October 4, 2011

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

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: