Neale Williams
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%.tx t
:: 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
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.%
:: echo the basic headers to the temp file
echo To: "Scripting Test" ^<me@mydomain.com.au^> > %tempmail%
echo From: "Admin" ^<them@theirdomain.com.au^
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
Can anyone help?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
When I change the script to use C:\program files\exchsrvr\vsi 1\pickup i get the error:
"the syntax is wrong"
"the syntax is wrong"
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks for the points, glad you got it working.
Blat is more flexible.
The whole code what you did can be achieved using a one liner.
Good luck.
Shaba