Upon finishing an email sending procedure, the Command Line Email utility returns an errorlevel value (an exit code) which indicates whether the email was sent without any errors or there was a warning or even a failure to deliver the message to an SMTP server. Errorlevel values returned, can be used in conditional processing in batch programs.
IF & ELSE
See how to use errorlevels for either getting more control over an email sending process in batch files or ensuring a successful task completion.
- if [not] errorlevel number command [else expression]
- if errorlevel number command
- if errorlevel number command else expression
- if not errorlevel number command
- if not errorlevel number command else expression
A simple example
An example of a simple batch script:
@echo off
:begin
febootimail -FROM john@example.net -TO doe@example.com -MSG "This message is sent from a Windows batch file."
if not errorlevel 5 goto end
echo Couldn't connect to server. Trying again...
goto begin
:end
echo End of batch program.
Errorlevels
A complete list of errorlevels returned by febootimail:
Errorlevel | Description |
---|---|
errorlevel 0 | No error. |
errorlevel 1 | Error opening file. |
errorlevel 2 | Error reading file. |
errorlevel 4 | Couldn't send message: server response (an additional error information may be shown). |
errorlevel 5 | Couldn't connect to server (an additional detailed error information may be shown). |
errorlevel 6 | Fields TO (or CC / BCC) and FROM are required. |
errorlevel 7 | Failed to initialize the Windows Sockets. |
errorlevel 8 | MFC initialization failed. |
errorlevel 9 | Invalid port number. Valid ports: 0-65535. |
errorlevel 10 | File: filename too big to fit in memory. |
errorlevel 16 | Failed to prepare email for sending. |
errorlevel 17 | Couldn't save EML file to disk. |
errorlevel 18 | TO parameter required when using SPLIT / TOEACH parameter. |
Warnings
A warning code is returned only if there are no errorlevels (1-10, 16-18). The email can be sent with some warnings.
Warning | Description |
---|---|
errorlevel 11 | Warning: Unknown parameter. |
errorlevel 12 | Warning: Bad IMG tag, image skipped. |
errorlevel 13 | Warning: Can't open image file: filename. |
errorlevel 15 | Warning: Can't open file: filename. |
errorlevel 19 | Warning: Missing parameter after specified command. |
errorlevel 20 | Warning: STARTTLS and SSL parameters are mutually exclusive. |
Other
Other messages without errorlevel:
No errorlevel | Description |
---|---|
- | There was an error accessing registry. Administrator rights might be necessary. |
- | Warning: Failed to check for updates. |
- | Warning: Can't open log file. |
- | Warning: Can't write log file. |
- | There was error(s) while sending message. |
- | e-mail(s) sent with some warnings. |
- | SPLIT / TOEACH parameter ignored when saving EML file. |
An advanced example
An example of advanced batch file script where errorlevel values are used as defined variables:
@echo off
febootimail -FROM john@example.net -TO doe@example.com -MSG "This is the second email message."
:: Perform conditional processing...
if %errorlevel% GTR 2 goto other
goto label%errorlevel%
:label0
echo A program had returned code 0... No error.
goto end
:label1
echo A program had returned code 1... Error opening file.
goto end
:label2
echo A program had returned code 2... Error reading file.
goto end
:other
echo A program had returned a code value larger than 2.
:end
echo End of the batch file script.
Resources
- Command Line Email parameters.
- Automation Workshop exit codes.
- Perform conditional processing in batch programs · microsoft.com website.
Need assistance?
If you have any questions, please do not hesitate to contact our support team.