Sendmail for Windows
Usage
Examples
SendMail is a command
line program for sending E-mail messages over the Internet.
It allows sending of
messages from the command line, CGI script or batch file. It is a Windows
version of the popular Unix Sendmail program. It allows easy migration
of perl scripts from Unix to Windows since it uses the same simple interface
as the Unix Sendmail. It can be easily integrated with your Website, or
Commercial Application. SendMail for Windows is an ideal Tool for Systems
Administrators, WebMasters, Software Developers, and Integrators.
Usage
Sendmail recipient...
This will read a message from standard input and send it to the specified
recipient.
options:
-t or -parseHeader
Scan message for recipients. SendMail will scan the message header for
lines containig To:, Cc:, and Bcc: and them to the list of recipients.
Only the message header is scanned, the scan terminates when the first
blank line is encountered.
The format of a simple
message with a header is given below, the cc and bcc addresses are
optional:
Subject: This is the
subject
From: John Doe <jdoe@sprynet.com>
To: John Doe <jdoe@sprynet.com>
Cc: John Doe <jdoe@sprynet.com>
Bcc: John Doe <jdoe@sprynet.com>
<== A BLANK LINE HERE
line 1 This is the body of the message
Line 2
etc
-messagefile=filename
Read message from file filename. By default message is read from stdin.
When reading from a file, the end of message is the end of file. When
reading from the console the message can be terminated by a single period
"." on a line by itself.
-from=senders_email_address
Specify the email address of the sender of the message. By default this
value is picked up from the sendmail.ini file, or the message if the -parseHeader
option is used.
-subject="The subject"
Specify the subject of the message. This option is used when sending a
plain text message file, which does not contain a header. The format of
a simple message without a header is given below:
line 1 This is the
body of the message
Line 2
etc
If this option is used
SendMail will generate a message header, for the message. This option
is not required if -parseHeader or -t is specified and the message contains
a subject line. If this option is not used, the message must contain a
header (see -parseHeader option).
-test
Send a test message. Recipients can be specified on the command line.
If no recipients are given then the message is sent to the email address
configured as the default senders email address.
-configure
SendMail will interactively ask you for configuration options. For more
details see the Installation section below.
-log=filename
Specify name of log file. By default log messages are logged to file "sendmail.log"
in the current directory. If Sendmail is run interactively, messages are
also logged to the console.
Running SendMail without
any arguments will cause it to print out a brief message including its
version number.
SendMail will return
a status code of 0 if successful, and non-zero if an error occured.
-console
This will cause SendMail to print log messages to standard output.
Use this option for testing SendMail when it is invoked from a CGI script.
Make sure to print out the "Content-type: text/html\n\n" header before
invoking SendMail. Perl scripts should also have "$|=1;" line near
the top of the script.
Return code
The return code can be tested from batch files and perl scripts
etc. Sendmail will return 0 on success and non-zero on failure.
Examples
1) sendmail -messagefile=msg.txt
-subject="This is the subject" name@host.com
This will send a plain text file file msg.txt to user name@host.com
2) sendmail <msg.txt
-subject="This is the subject" name@host.com
This will send a plain text file file msg.txt to user name@host.com. This format can only be
used when entering the command from a DOS prompt.
3) sendmail -t -messagefile=msg.txt
This will send a text file file msg.txt. The subject and recipient are
determined from the message file. The message file must contain a header
in the format given earlier.
4) Below is a perl script
example:
open (MAIL, "|sendmail
-t");
print MAIL "To: Your Name <name\@host.com>\n";
print MAIL "From: My Name <myname\@myhost.com>\n";
print MAIL "Subject: This is the subject\n\n";
print MAIL "This is the body of the message\n";
print MAIL "This is line 2\n";
close (MAIL);
5) Below is a perl cgi
example:
$| = 1;
print "Content-type: text/html\n\n";
print "<html><body>\n";
print "Sending message<br>\n";
print "</body></html>\n";
$mailprog = 'sendmail.exe';
open (MAIL, "|$mailprog -t");
print MAIL "To: Your Name <name\@host.com>\n";
print MAIL "From: My Name <myname\@myhost.com>\n";
print MAIL "Subject: This is the subject\n\n";
print MAIL "This is the body of the message\n";
print MAIL "This is line 2\n";
close (MAIL);
6) Below is a perl cgi
example which does not rely on io redirection:
$| = 1;
print "Content-type: text/html\n\n";
print "<html><body>\n";
print "Sending message<br>\n";
print "</body></html>\n";
$mailprog = 'sendmail.exe';
$tempfile = "temp.msg";
open(MAIL,">$tempfile");
print MAIL "To: Your Name <name\@host.com>\n";
print MAIL "From: My Name <myname\@myhost.com>\n";
print MAIL "Subject: This is the subject\n\n";
print MAIL "This is the body of the message\n";
print MAIL "This is line 2\n";
close (MAIL);
system("$mailprog
-t -messagefile=$tempfile");
|