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);
8 Responses to “Sendmail Linux Examples”
Trackbacks / Pingbacks
- - October 4, 2011
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.
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.
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
How did you make a site look this awesome!? Email me if you get the chance and share your wisdom. Id be thankful.
Is it okay to insert a portion of this on my personal weblog if perhaps I post a reference point to this web page?
Yes no problem
Nice article, thank you! I really love it.