Home › Forums › Bug Reports › SwithMail Bug Reports › cant get errorlevel to work
Tagged: errorlevel
- This topic has 9 replies, 2 voices, and was last updated 5 months, 3 weeks ago by
onlinestatements.
-
AuthorPosts
-
-
Cannot get
echo %errorlevel%
to equal 1 when swith fails to send an emailMy one line swith command is below.
%confirmdir%\SwithMail.exe /s /from “test@test.com” /name “My Company Name” /pass “mypassword” /server “mail.test.com” /p “587” /SSL /to “!emailadds!” /sub “File Confirmation – READ ME” /a “%confirmdir%\confirms\extract\!attachfile!” /btxt “%confirmdir%\confirms\!filename: =!!fileext: =!!atname!” /l “%confirmdir%\slog.txt”
-
if you add
/test
to the end, do you get an error message pop up, or does it say ‘success’? -
It pops up and says
Failure sending mail
along with other things
but when I dismiss this the batch runs
echo %errorlevel%
and outputs 0 -
What are the ‘other things?’
-
it just shows why it failed.
I trigger the failure by making my password incorrect.
I have also triggered the failure by unplugging my ethernet cable.
both trigger methods triggers the failure popup with /test
but neither set the %errorlevel% to 1 -
also figured out a workaround for the errorlevel like I did with the no attachment found issue:
for %%f in (%confirmdir%\slog.txt) do for /f %%i in ('find /v /c "" ^< %%f') do set errorlinenum=%%i
for /f "tokens=1 delims= " %%a in (%confirmdir%\slog.txt) do set errormsg=%%a
if /i "!errormsg!" EQU "Failure" (echo. & echo Message Send Failed & set /a failedcount+=1 & move /y "%confirmdir%\confirms\!filename: =!!fileext: =!!atname!" %confirmdir%\confirms\failed > nul & move /y "%confirmdir%\confirms\!filename: =!.ini!atname!" %confirmdir%\confirms\failed > nul & if exist "%confirmdir%\confirms\!attachname!!atname!" move /y "%confirmdir%\confirms\!attachname!!atname!" %confirmdir%\confirms\failed > nul) else (echo. & echo Message Send Successfull & set /a successcount+=1)
This searches the last line of the log file after each failed attempt for the word Failure and sets failedcount+=1
Then moves all associated email files pertaining to that email to a failed folder-
This reply was modified 5 months, 3 weeks ago by
onlinestatements.
-
That’s very nice! I should probably do the same type of search for “Failure” on the back end. I’ll look into that as well.
-
I only have +=1 because I keep track of the number of failures and display it on a refreshing report screen.
Most people probably wont need as many files and variables as I do for the emails.
Did you see my workaround for the attachment not found issue on the other thread?The cmail command line email toold has an option for skipping attachment checking and allowing sending.
maybe you can look at their code if you can get it to see how they implemented it.
https://www.inveigle.net/cmail/usage.shtml
-
-
This reply was modified 5 months, 3 weeks ago by
-
My previous solution didn’t work for every type of failure.
Not all failure messages place the word failure on the last line of the log file.
So I changed the script to find the word Success on the last line and mark as failure if NOT equals Success.for %%f in (%emaildir%\log.txt) do for /f %%i in ('find /v /c "" ^< %%f') do set errorlinenum=%%i
The above line finds the last non blank line in your log file. enable log with /l logfile.txtfor /f "tokens=5 delims= " %%a in (%confirmdir%\log.txt) do set errormsg=%%a
The above line uses a space delimiter and captures the 5th word which should be Success if message successful.if /i "%errormsg%" NEQ "Success" (echo. & echo Message Send Failed & set /a failedcount+=1 & move /y "%emaildir%\emailfiles\%emailbody%" %emaildir%\emailfiles\failed > nul & move /y "%emaildir%\emailfiles\%emailaddress%" %emaildir%\emailfiles\failed > nul & if exist "%emaildir%\emailfiles\%attachment%" move /y "%emaildir%\emailfiles\%attachment%" %emaildir%\emailfiles\failed > nul) else (echo. & echo Message Send Successfull & set /a successcount+=1)
The above line carries out commands based on if the email was successful or not. > nul hides the file moved output. -
just found another issue with new solution.
if swithmail doesnt run for some reason maybe a symbol in the attachment filename or something then it quits before it can write anything to the log file.
if the previous log entry said success then it will mark this failure as a successful send.
so i just added an append to log file line before the swith.exe line executes.
something like:echo New Entry - %date% - %time% - %emailaddresses% - %emailsubjext% - %attachfilename%>>"%emaildir%\log.txt"
This line will also help identify the exact email that failed.
%now% cant be used outside of the swith exe line so you will need to use your own or built in cmd date and time variables.-
This reply was modified 5 months, 3 weeks ago by
onlinestatements.
-
This reply was modified 5 months, 3 weeks ago by
onlinestatements.
-
This reply was modified 5 months, 3 weeks ago by
-
-
AuthorPosts
- You must be logged in to reply to this topic.