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);

16 thoughts on “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. Pingback: free ipad
  4. 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

  5. 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.

  6. 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!

  7. 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.

  8. 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.

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