I have a problem with stopping a service and starting it again and want to be notified when the process runs and let me know what the result is.
Here's the scenario, I have a text file output of an "sc" command. I want to send that file but not as an attachment. Also, I want to see the initial status quickly in the subject of the email.
Here's the 'servstop.txt' file contents:
[SC] StartService FAILED 1058:
The service cannot be started, either because it is disabled or because it has no enabled devices associated with it.
I want the subject of the email to be "Alert Service Start: [SC] StartService FAILED 1058" and the body to contain the entire error message above.
I will put my current method in an answer below using a program called blat to send me the result.
Here's how I'm doing this. First I got blat mail (public domain smtp mailer) and dropped it into d:\blat directory. My Exchange server allows me to email without id/password and just assumes that I am the person in the 'from' field of the blat command.
@echo off
sc start Alerter >servstop.txt
SetLocal EnableDelayedExpansion
set content=
set subj=
for /F "delims=" %%i in (servstop.txt) do set content=!content! %%i
for /f "tokens=1 delims=:" %%s in ("%content%") do set subj=%%s
d:\blat\blat.exe -body "%content%" -to my-email@foo.bar -f my-email@foo.bar -server smtp.foo.bar -s "Alert Service Start:%subj% " -log d:\blat\blat.log
EndLocal