A New Internet Library: Add Your Website/Blog or Suggest A Website/Blog to our Free Web Directory http://anil.myfunda.net.

Its very simple, free and SEO Friendly.
Submit Now....

Wednesday, February 13, 2008

Sending Mail From BATCH FILE

The sample script below sends an email using IIS's SMTP service running on the local machine.

Notes:
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:
echo.>>%tempmail%
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" ^<test@paulsadowski.com^> > %tempmail%
echo From: "Me" ^<me@my.com^> >> %tempmail%
echo Subject: Test2 >> %tempmail%
:: echo the blank line that separates the header from the body text
echo.>>%tempmail%
:: 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=
endlocal

No comments:

Post a Comment

Post your comments here:

Dotnet-Interviews