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:
Here is a rundown of what I am doing:
mailsend1.17b14.exe -to <snip personal info> -log temp.txt -attach test.txt
.\Tail\Tail -1 temp.txt > temp2.txt
Set /p Message=<temp2.txt
Set Cmess=Mail sent successfully
If "Message"=="Cmess" ( Echo Correct ) Else ( Echo Wrong )
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).
The next 2 lines 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).
The next line creates a second variable that contains the desired output (i.e. "Mail sent successfully")
The next two lines echos the contents of the variables.
And finally, the last line compares the two variable and takes a particular action depending on whether the two variables are equal or not.
The comparison at the end is where I'm having problems. Every time I run the script, the last line I get printed on the screen 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 commands 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.
Set /p Cmess=<temp2.txt
Can anyone help me get this script to work or help me script a means of checking the log file for "Mail sent successfully"? I would greatly appreciate any help I get.
If it interests anyone, this is what the log file contains if an email gets sent successfully:
07-Jun-2014 08:17:28.172: mailsend v@(#) mailsend v1.17b14
07-Jun-2014 08:17:33.011: Mail sent successfully