FB_SmtpV3

FB_SmtpV3 1:

The function block sends a byte stream to an ADS device. The TwinCAT SMTP Server must be running on the target system in order to receive the stream and send it as an email. Once the byte stream is sent, the email is sent.

VAR_INPUT

VAR_INPUT
    sNetId      : T_AmsNetID; (* AmsNetID *)
    sSmtpServer : T_MaxString; (* Smtp Server address ( IP or Name) *)
    sUsername   : T_MaxString; (* Smtp Username *)
    sPassword   : T_MaxString; (* Smtp Password *)
    nEncryption : UDINT;    (* 0=NONE, 1=STARTTLS, 2=TLS *)
    sFrom       : T_MaxString; (* Sender string *)
    sTo         : T_MaxString; (* To recipient string *)
    sCc         : T_MaxString; (* Cc recipient string *)
    sBcc        : T_MaxString; (* Bcc recipient string *)
    sSubject    : T_MaxString; (* Subject string *)
    pMessage    : POINTER TO STRING;    (* Pointer to the message *)
    cbMessage   : UDINT;    (* Message lenght in byte to send *)
    bExecute    : BOOL;
    tTimeout    : TIME := T#20s;
END_VAR

sNetId: AmsNetID on which the TwinCAT SMTP Server is running.

sSmtpServer: name or IP of the SMTP server to reach.

sUsername: user name of the SMTP server to be reached.

sPassword: password of the SMTP server to be reached.

nEncryption: SMTP encryption type:
0 = NONE
1 = STARTTLS
2 = TLS

sFrom: a string containing the email address or name of the sender. The sender must be specified. The string is limited to 255 characters.

sTo: a string containing the email address of the recipient. At least one recipient must be entered. However, it is also possible to enter multiple addresses. These must be separated by a semicolon. The string is limited to 255 characters.

sCc: a string containing the email address of additional recipients (cc=carbon copy). It is possible to enter multiple addresses of recipients, these must then be separated by a semicolon. However, the string can also remain empty. A copy of the email will be sent to the recipient(s). The recipient's email address is visible to other recipients. The string is limited to 255 characters.

sBcc: a string containing the email addresses of additional recipients (Bcc = blind carbon copy). It is possible to enter multiple addresses of recipients, these must then be separated by a semicolon. However, the string can also remain empty. A copy of the email will be sent to the recipient(s). The recipients' email address is not visible to other recipients. The string is limited to 255 characters.

sSubject: this string contains the subject of the email. If the email is sent without a subject, the computer name of the sender is automatically written in the subject line (e.g. "Email sent by: CX-00762C"). The subject line string is limited to 255 characters.

pMessage: this parameter specifies the address of the string containing the message text. If the email is sent without text, the date and time will be inserted automatically (e.g. "Mail send at Thu, 23 Mar 2006 02:31:44 -0800"). The address of the string can be specified with the ADR operator.

cbMessage: length of the email text. The length can be specified by the LEN operator.

bExecute: the function block is enabled by a rising edge at this input variable.

tTimeout: the maximum time allowed to execute a command.

VAR_OUTPUT

VAR_OUTPUT
    bBusy  : BOOL;
    bError : BOOL;
    nErrId : UDINT;
END_VAR

bBusy: the output variable remains TRUE until the function block has executed a command, but only until tTimeOut has expired.

bError : the output variable is switched to TRUE as soon as an error occurs during the execution of the command. The command-specific error is contained in nErrId.

nErrId: contains the command-specific error code of the last executed command

FB_SmtpV3 2:

Make sure, that you don't use \o within byte-arrays. Otherwise the Message will be cut.

The maximum amount of characters, that can be used in a message, is 510.725 - you have 1275 characters for From, To, Cc, Bcc and Subject.

Requirements

Development environment

Target system type

PLC libraries to be linked

TwinCAT v3.0.0

PC or CX (x86)

Tc2_Smtp