June 19, 2019 at 11:36 am #551
to equal 1 when swith fails to send an email
My one line swith command is below.
%confirmdir%\SwithMail.exe /s /from “firstname.lastname@example.org” /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”
June 19, 2019 at 11:42 am #555
if you add
/testto the end, do you get an error message pop up, or does it say ‘success’?
June 19, 2019 at 11:51 am #557
It pops up and says
Failure sending mail
along with other things
but when I dismiss this the batch runs
and outputs 0
June 19, 2019 at 11:54 am #560
What are the ‘other things?’
June 19, 2019 at 12:01 pm #562
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
June 19, 2019 at 7:41 pm #572
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 11 months, 2 weeks ago by onlinestatements.
June 19, 2019 at 7:44 pm #576
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.
June 19, 2019 at 8:27 pm #578
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.
June 20, 2019 at 8:30 pm #582
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.txt
for /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.
June 20, 2019 at 9:44 pm #588
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.
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.
March 2, 2020 at 6:54 am #694artybParticipant
Thank you for you work on this and for releasing it. I’m also having difficulties with errorlevel. Swithmail seems to frequently not save the logfile, so the workaround above wouldn’t work either.
What is tested for in the errorlevel check? I’ve entered an unknown email address which produces an undeliverable response, but both the CLI and Test function in the GUI report no errors. I’m trying to make a way of resending the email if it isn’t sent, eg email server issue.
April 14, 2020 at 11:33 am #709artybParticipant
A response or update to swithmail would be really helpful.
I hope you all are well!
May 5, 2020 at 9:19 am #723
The error level is strictly an OS-level error. I’m not getting any replies back from servers (as it’s not the mail server – it’s sending TO the mail server to deliver), so I have no way to get responses back other than what’s available through the .NET mail function.
As for the the log files — it should always write them if the file’s not locked / in use. If you’re running multiple copies at the same time, one process may have a lock on the log file, but that’s just a guess w/o more testing.
- You must be logged in to reply to this topic.