Greetings
I am attempting to write a batch script that uses a program called Mailsend to send an email. The script then examines Mailsend's log output to determine if the email was successfully sent.
This is what I have so far:
The first line sends the email. The second and third use a program called Tail to delete all lines except the last one from the log file (the last line contains the output I'm looking for). I then assign the contents of the log file to a variable then truncate the first 26 characters (date and time info that I don't need). I then create a second variable with the desired output then compare the two.
The comparison at the end is where I'm having problems. Every time I run the script, the last line I get is "Wrong" (i.e. the "Echo Wrong" command is executed meaning "Message" does not equal "Cmess"). This happens even when the email was sent successfully. I've tried various things and I haven't managed to get the "Echo Correct" command to ever execute, even when the output of the two Echo command just before is exactly the same. I've even tried changing the "Set Cmess" line to:
...and the output for the comparison is still "wrong". I can only think that there must be something wrong with how I structured the comparison.
Can anyone help me get this script to work or help me script a means of checking the log file for "Mail sent successfully"?
If it interests anyone, this is what the log file contains if an email gets sent successfully:
I am attempting to write a batch script that uses a program called Mailsend to send an email. The script then examines Mailsend's log output to determine if the email was successfully sent.
This is what I have so far:
Code:
mailsend1.17b14.exe -to <snip personal info> -log temp.txt -attach test.txt
.\Tail\Tail -1 temp.txt > temp2.txt
Del temp.txt
Set /p Message=<temp2.txt
Set Message=%Message:~26%
Set Cmess=Mail sent successfully
Echo %Message%
Echo %Cmess%
If "Message"=="Cmess" ( Echo Correct ) Else ( Echo Wrong )
The comparison at the end is where I'm having problems. Every time I run the script, the last line I get is "Wrong" (i.e. the "Echo Wrong" command is executed meaning "Message" does not equal "Cmess"). This happens even when the email was sent successfully. I've tried various things and I haven't managed to get the "Echo Correct" command to ever execute, even when the output of the two Echo command just before is exactly the same. I've even tried changing the "Set Cmess" line to:
Code:
Set /p Cmess=<temp2.txt
Set Cmess=%Cmess:~26%
Can anyone help me get this script to work or help me script a means of checking the log file for "Mail sent successfully"?
If it interests anyone, this is what the log file contains if an email gets sent successfully:
Quote:
07-Jun-2014 08:17:28.172: mailsend v@(#) mailsend v1.17b14 07-Jun-2014 08:17:33.011: Mail sent successfully |