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:
Here is a rundown of what I am doing:
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.
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:
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 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:
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"? 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:
Code:
07-Jun-2014 08:17:28.172: mailsend v@(#) mailsend v1.17b14
07-Jun-2014 08:17:33.011: Mail sent successfully
My Computer
System One
-
- OS
- Windows 8.1
- Computer type
- PC/Desktop
- System Manufacturer/Model
- Custom built
- CPU
- Intel Core i5 2500K
- Motherboard
- MSI Z77A-G43
- Memory
- 16GB DDR3 133MHz
- Graphics Card(s)
- Geforce 580
- Browser
- Palemoon (Optimised Firefox)
- Antivirus
- Windows Defender & Emsisoft Antimalware