Windows Cmd Shell
 Send mail from a batch file
The sample script below sends an email using IIS's SMTP service running on the local machine.

Special shell characters such as < and > must be escaped using the caret character ^
IIS requires only a minimal set of headers followed by a blank line which separates
the header from the body text. To create the blank line use the following line in
your script:
It is critical that there be no extra spaces in that line! Use exactly as shown.

The move command moves the temporary file with the mail into the pickup directory.
The pickup dir is typically c:\inetpub\mailroot\pickup but this may be different on
your system.

The account under which this script runs must have write permission to the
pickup directory. Once the file is sent the server itself deletes the file from
the pickup directory. DO NOT attempt to write the file directly to the pickup
directory. Always move it from a temp directory. IIS will attempt to send
any file in the pickup directory as soon as it detects it. Therefore you may
not have completed writing to the file before IIS tries to send and deletes the file.
Always move the file to the pickup directory.

@echo off & setlocal
:: set the temp file location
set tempmail=%temp%\tempmail.%random%.txt
:: echo the basic headers to the temp file
echo To: "Scripting Test" ^<^> > %tempmail%
echo From: "Me" ^<^> >> %tempmail%
echo Subject: Test2 >> %tempmail%
:: echo the blank line that separates the header from the body text
:: echo the body text to the temp file
echo First line of body text.>> %tempmail%
echo Second line of body text.>> %tempmail%
:: move the temp file to the mail pickup directory
:: adjust this location for your system
move %tempmail% c:\inetpub\mailroot\pickup
set tempmail=

© 2003 by Paul R. Sadowski   
All Rights Reserved. Used By Permission.  
Comments to: Scripting