FB_Smtp

This function block uses the SMTP protocol (simple mail transfer protocol) to send e-mails. The function block can, for instance, be used to send errors, diagnostic information, or warnings in the form of e-mails. The recipients' addresses are passed as strings to the sTo, sCc, sBcc and sSubject input variables. The maximum string length for recipients' addresses is limited to 80 characters in order to save resources. The string with the mail text itself may, however, be longer.
VAR_INPUT
VAR_INPUT
bStart : BOOL;
sSmtpServer : STRING(15);
sFrom : STRING;
sTo : STRING;
sCc : STRING;
sBcc : STRING;
sSubject : STRING;
pMail : DWORD;
tTimeOut : TIME;
END_VAR
bStart: The function block is activated by a rising edge at this input.
sSmtpServer: IP address of the SMTP server as a string.
sFrom: A string containing the e-mail address of the sender. If the string supplied is empty, then the Bus Controller generates an e-mail address from the name of the Bus Controller and the MAC ID. The maximum string length is limited to 80 characters. It is possible to enter multiple recipient addresses separated by semicolons.
sTo: A string containing the e-mail address of the recipient. A valid e-mail address must be given. The maximum string length is limited to 80 characters. It is possible to enter multiple recipient addresses separated by semicolons.
sCc: A string containing the e-mail address of a further recipient (Cc = carbon copy). This string can also be empty. A copy of the e-mail is sent to this recipient. The e-mail address of this recipient is visible to other recipients. The maximum string length is limited to 80 characters. It is possible to enter multiple recipient addresses separated by semicolons.
sBcc: A string containing the e-mail address of a further recipient (Bcc = blind carbon copy). This string can also be empty. A copy of the e-mail is sent to this recipient. The e-mail address of this recipient is not visible to other recipients. The maximum string length is limited to 80 characters. It is possible to enter multiple recipient addresses separated by semicolons.
sSubject: A string containing the e-mail's subject line. This string can also be empty. The maximum string length is limited to 80 characters.
pMail: The address (a pointer) to a null-terminated string containing the e-mail text. This string can also be empty. The address of the string can be determined with the ADR operator.
tTimeOut: Maximum time allowed for the execution of the command.
VAR_OUTPUT
VAR_OUTPUT
bBusy : BOOL;
bError : BOOL;
iErrorId : WORD;
END_VAR
bBusy: This output remains TRUE until the function block has executed a command, but at the longest for the duration supplied to the tTimeOut input.
bError: This output is switched to TRUE as soon as an error occurs during the execution of a command. The command-specific error code is contained in iErrorId.
iErrorId: Contains the command-specific error code of the most recently executed command (table).
Error code (hex) |
Description |
---|---|
0x8000 |
SMTP server not found. |
0x8001 |
Resource error. |
0x8002 |
Socket resource error. |
0x8003 |
Connection fault. |
0x8004 |
Communication fault. |
0x8005 |
Rx error. Communication time exceeded. |
0x8006 |
Rx error. Communication fault. |
0x8007 |
Rx error. Frame error. |
0x8008 |
Communication error. Wrong response. |
0x8009 |
Tx error. Communication fault. |
0x800A |
Communication shutdown error. |
0x800B |
Communication timeout. |
0x8010 |
Invalid parameter. |
Example of a call in FBD
PROGRAM MAIN
VAR
fbSMTP : FB_Smtp;
bSend : BOOL;
sMsg : STRING(100):='Test';
bBusy : BOOL;
bError : BOOL;
nErrId : UDINT;
END_VAR

In this example, a rising edge at the bStart input sends a mail to 4 recipients.
Development environment |
Target platform |
PLC libraries to be linked |
---|---|---|
TwinCAT v2.10.0 and above |
BX9000 (165) firmware version >=1.12 |
TcBaseBX9000.lbx |