Solved

Send Email via batch file

Posted on 2010-09-20
5
875 Views
Last Modified: 2012-05-10
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
0
Comment
Question by:nealerocks
5 Comments
 
LVL 14

Accepted Solution

by:
Erik Pitti earned 450 total points
Comment Utility
Try using a copy, then delete the original file instead of a move.  A copy operation updates the NTFS filesystem differently than a move if the source and destination directories are on the same drive letter.

copy %tempmail% c:\inetpub\mailroot\pickup
del %tempmail%

Also you should be using the pickup folder under mailroot in exchange

Alternatively, you can use the BLAT.exe smtp client to send mail instead of writing directly to the pickup folder.

http://www.blat.net/

0
 
LVL 14

Expert Comment

by:Shabarinath Ramadasan
Comment Utility
Yea.. Agree with Chakote..
Blat is more flexible.
The whole code what you did can be achieved using a one liner.

Good luck.
Shaba
0
 
LVL 12

Author Comment

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

"the syntax is wrong"
0
 
LVL 31

Assisted Solution

by:MegaNuk3
MegaNuk3 earned 50 total points
Comment Utility
try putting " around the long path name like "C:\program files\exchsrvr\vsi 1\pickup"

OR
use the short name like c:\progra~1\exchsrvr\vs~1 ( you'll have to check that is correct, I am not in front of an Exchange server to test that at the moment)
0
 
LVL 31

Expert Comment

by:MegaNuk3
Comment Utility
Thanks for the points, glad you got it working.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Lync 2013 and Skype for Business 4 22
Publishing OWA on TMG 2010 2 23
VBA Shell can't Find Word document 11 39
cached or not 5 38
Resolve DNS query failed errors for Exchange
Scam emails are a huge burden for many businesses. Spotting one is not always easy. Follow our tips to identify if an email you receive is a scam.
In this video we show how to create an Address List in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Organization >> Ad…
how to add IIS SMTP to handle application/Scanner relays into office 365.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now