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 (pointer) of 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, which must not be exceeded during command execution.
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 Timeout input.
bError: this output is switched to TRUE if 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. |
Sample 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 sample, a rising edge at the bStart input sends a mail to 4 recipients.
Requirements
Development environment | Target platform | PLC libraries to include |
---|---|---|
TwinCAT v2.7.0 and above | BC9xxx (165) firmware version >=0xB6 | TcSMTPBC.Lb6 |