| Newsgroups |
gmane.mail.blat |
| Message-ID |
<[email protected]> |
We almost finished our tsk to automatically send result reports files (In either .txt or xlsx formats) to customers of our POS System in Thailand.
I will post more details of our Solution later, but right now we have an issue with Error Handling in Blat.
I demonstrate this here on a Batch file we want to use to send a specific result to a customer. Once working, we will replace the to email, Date and other Data with variable, but here is a basic example with some extra log commands for debug:
rem @echo off
REM New Customers Email
REM V. 1.01
SET LOGFILE=C:\POS\Debug\MailLog.txt
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"
set "timestamp=%HH%:%Min%"
set "datestamp=%YY%-%MM%-%DD%"
ECHO ----- START ------%datestamp% %timestamp% >> %LOGFILE%
ECHO Now sending Order info to Management >> %LOGFILE%
"C:\POS\Blat\blat.exe" -body "Here are New Order Details from RESTAURANT" -attach "C:\POS\PrintFiles\*.xlsx" -tf "C:\POS\BlatConfig\sprecipients.txt" -subject "RESTURANT Food Orders from %datestamp%" -debug -log %LOGFILE% >> %LOGFILE%
IF !ERRORLEVEL!==13 GOTO :ERROR13
IF !ERRORLEVEL!==12 GOTO :ERROR12
IF !ERRORLEVEL!==5 GOTO :ERROR5
IF !ERRORLEVEL!==4 GOTO :ERROR4
IF !ERRORLEVEL!==3 GOTO :ERROR3
IF !ERRORLEVEL!==2 GOTO :ERROR2
IF !ERRORLEVEL!==1 GOTO :ERROR1
GOTO :SUCCESS
:ERROR13
ECHO ERROR: Error opening temporary file in temp directory >> "%LOGFILE%"
GOTO :FINALISE
:ERROR12
ECHO ERROR: -server or -f options not specified and not found in registry >> "%LOGFILE%"
GOTO :FINALISE
:ERROR5
ECHO ERROR: Error Reading File (message text) >> "%LOGFILE%"
GOTO :FINALISE
:ERROR4
ECHO ERROR: File (message text) not of type FILE_TYPE_DISK >> "%LOGFILE%"
GOTO :FINALISE
:ERROR3
ECHO ERROR: Error reading the file (message text) or attached file >> "%LOGFILE%"
GOTO :FINALISE
:ERROR2
ECHO ERROR: File (message text) does not exist, the server actively denied our connection or the mail server doesn't like the sender name. >> "%LOGFILE%"
GOTO :FINALISE
:ERROR1
ECHO ERROR: File name (message text) not given or Bad argument given, Unable to open SMTP socket, SMTP get line did not return 220, command unable to write to socket, Server does not like To: address or Mail server error accepting message data. >> "%LOGFILE%"
GOTO :FINALISE
:FINALISE
ECHO Error! Error! Error! >>"%LOGFILE%"
GOTO :EXIT
:SUCCESS
ECHO Success! Success! Success! >>"%LOGFILE%"
ECHO Here we delete the sent Files >>"%LOGFILE%"
DEL /F /Q C:\POS\PRINTFILES\*.xlsx" >>"%LOGFILE%"
GOTO :EXIT
:EXIT
ECHO ----- END -------------------- >> "%LOGFILE%"
ECHO.>> "%LOGFILE%"
ECHO.>> "%LOGFILE%"
ECHO.>> "%LOGFILE%"
The batch successfully sends the email with the attachment.
Error handling is also logged correctly (and files not deleted)in case of SMTP server Parameters miscnfigured (WE store the Parameters in Registry; previous issues are resolved)
But in case of missing Internet connection we receive the following Log entry:
----- START ------17-11-26 10:04
Now sending Order info to Management
Blat v3.2.17 (build : Aug 10 2016 22:32:21)
32-bit Windows, Full, Unicode
Read 1 TO address from C:\Bartender\BlatConfig\sprecipients.txt
Error: Connection to server was dropped.
*** Error *** SMTP server error
Error: Not a socket.
Error: Not a socket.
Success! Success! Success!
Here we delete the sent Files
----- END --------------------
Seems we don't catch this specific Error! How can this be resolved?
Manfred