Forum Replies Created

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • in reply to: cant get errorlevel to work #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.

    in reply to: cant get errorlevel to work #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.

    in reply to: cant get errorlevel to work #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

    in reply to: cant get errorlevel to work #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

    onlinestatements
    Participant
    1 pt

    the echo filename is of course optional.
    I just wanted to display the name of the attachment when sending the email if an attachment exists.

    onlinestatements
    Participant
    1 pt

    I figured out a workaround and can get the email to send with or without an attachment.

    if exist "%confirmdir%\confirms\!attachname!!atname!" echo !filename: =!.attachments!atname! & set attachexist=yes
    if "!attachexist!" EQU "yes" set checkattach=^/a "%confirmdir%\confirms\extract\!attachfile: =!"

    then in the swith command line I place the checkattach !variable!
    between the subject and body text settings like:

    /sub "email subject" !checkattach! /btxt "emailbodytext.txt"

    so now if the attachment doesn’t exist the variable will be empty and no /a will be attached to the command

    Also if you are running your script in a for loop be sure to clear the checkattach variable at the start of the loop like
    set checkattach=

    in reply to: cant get errorlevel to work #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

    in reply to: cant get errorlevel to work #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

    onlinestatements
    Participant
    1 pt

    I second this feature to ignore attachment doesnt exist
    Not all of my messages have attachments and I don’t want the ones that don’t to fail to send

Viewing 9 posts - 1 through 9 (of 9 total)