FB_SmtpV3

FB_SmtpV3 1:

The function block FB_SmtpV3 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.

FB_SmtpV3 2: Inputs

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

Name

Type

Description

sNetId

T_AmsNetID

AmsNetID on which the TwinCAT SMTP Server is running.

sSmtpServer

T_MaxString

Name or IP of the SMTP server to be reached

sUsername

T_MaxString

User name of the SMTP server to be reached

sPassword

T_MaxString

Password of the SMTP server to be reached

nEncryption

UDINT

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

sFrom

T_MaxString

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

sTo

T_MaxString

A string containing the recipient's email address. 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

T_MaxString

A string containing the email addresses of additional recipients (cc=carbon copy). It is possible to enter multiple recipient addresses. These must then be separated by a semicolon. 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

T_MaxString

A string containing the email addresses of additional recipients (Bcc = blind carbon copy). It is possible to enter multiple recipient addresses. These must then be separated by a semicolon. 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

T_MaxString

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

POINTER TO STRING

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

UDINT

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

bExecute

BOOL

The function block is enabled by a rising edge on this input variable.

tTimeout

TIME

The maximum time allowed to execute a command.

FB_SmtpV3 3: Outputs

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

Name

Type

Description

bBusy

BOOL

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

bError

BOOL

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

UDINT

Contains the command-specific error code of the most recently executed command.

FB_SmtpV3 4:

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 platform

PLC library to include

TwinCAT v3.0.0

PC or CX (x86)

Tc2_Smtp