Link to home
Start Free TrialLog in
Avatar of Neale Williams
Neale WilliamsFlag for Australia

asked on

Send Email via batch file

I am trying to create a batch file that will send an email to myself. I want to be alerted when services on Windows servers stop.
This will be used on Windows Server 2003 with Exchange 2003. The code I am using is below:

@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" ^<me@mydomain.com.au^> > %tempmail%
echo From: "Admin" ^<them@theirdomain.com.au^> >> %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

The file gets created in the c:\inetpub\mailroot\pickup directory but then nothing happens. There is also a pickup directory under the exchange folders but that didn't work either.
Can anyone help?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Erik Pitti
Erik Pitti
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Shabarinath TR
Yea.. Agree with Chakote..
Blat is more flexible.
The whole code what you did can be achieved using a one liner.

Good luck.
Shaba
Avatar of Neale Williams

ASKER

When I change the script to use C:\program files\exchsrvr\vsi 1\pickup i get the error:

"the syntax is wrong"
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the points, glad you got it working.