Home Forums Bug Reports SwithMail Bug Reports cant get errorlevel to work

Tagged: 

Viewing 10 reply threads
  • Author
    Posts
    • #551 Score: 0
      onlinestatements
      Participant
      1 pt

      Cannot get
      echo %errorlevel%
      to equal 1 when swith fails to send an email

      My 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”

    • #555 Score: 0
      tbare
      Keymaster
      1 pt

      if you add /test to the end, do you get an error message pop up, or does it say ‘success’?

    • #557 Score: 0
      onlinestatements
      Participant
      1 pt

      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

    • #560 Score: 0
      tbare
      Keymaster
      1 pt

      What are the ‘other things?’

    • #562 Score: 0
      onlinestatements
      Participant
      1 pt

      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

    • #572 Score: 0
      onlinestatements
      Participant
      1 pt

      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

      • #576 Score: 0
        tbare
        Keymaster
        1 pt

        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.

        • #578 Score: 0
          onlinestatements
          Participant
          1 pt

          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

    • #582 Score: 0
      onlinestatements
      Participant
      1 pt

      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.

    • #588 Score: 0
      onlinestatements
      Participant
      1 pt

      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.

    • #694 Score: 0
      artyb
      Participant

      Hi,

      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.
      Best Wishes

    • #709 Score: 0
      artyb
      Participant

      Hi,
      A response or update to swithmail would be really helpful.

      I hope you all are well!

    • #723 Score: 0
      tbare
      Keymaster
      1 pt

      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.

Viewing 10 reply threads
  • You must be logged in to reply to this topic.