FB_Smtp

FB_Smtp 1:

The function block FB_Smtp sends a byte stream to an ADS remote device via ADS. The TwinCAT ADS SMTP service must be running on the remote ADS device, so that the byte stream can be received and processed into an email. The email is then sent after bytesteam processing.
Please note that the SMTP server does not support password verification, as the TwinCAT ADS SMTP service does not log in to the server via password verification.

FB_Smtp 2: Inputs

VAR_INPUT
    sNetId    : T_AmsNetID;  (* AmsNetID *)
    sSmtpServer : T_MaxString; (* Smtp-Server address (IP or Name) *)
    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  : DWORD;       (* Pointer to the message *)
    cbMessage : UDINT;       (* Messagelenght to send *)
    bExecute  : BOOL;
    tTimeout  : TIME := T#20s;
END_VAR

Name

Type

Description

sNetId

T_AmsNetID

AmsNetID, on which the TwinCAT mail server runs.

sSmtpServer

T_MaxString

Name or IP of the SMTP server

sFrom

T_MaxString

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

sTo

T_MaxString

A string containing the email addresses of the recipients. Several addresses can be specified. These must then be separated by a semicolon. At least one recipient has to be specified. The string is limited to 255 characters.

sCc

T_MaxString

A string containing an email address of a further recipient (cc=carbon copy). This string can also be empty. A copy of the email is sent to this recipient. The email address of this recipient is visible to other recipients. It is possible to enter multiple recipient addresses separated by semicolons. The string is limited to 255 characters.

sBcc

T_MaxString

A string containing the email address of a further recipient (Bcc = blind carbon copy). This string can also be empty. A copy of the email is sent to this\these recipient\s. The email address of this recipient is not visible to other recipients. It is possible to enter multiple recipient addresses separated by semicolons. The string is limited to 255 characters.

sSubject

T_MaxString

A string containing the subject line for the email. The email can also be sent without a subject. The name of the sending computer is then automatically entered in the subject line (e.g., “Mail sent from: CX_00762C”). The string for the subject line is limited to 255 characters.

pMessage

DWORD

The address (a pointer) to a null-terminated string containing the email text. The email can also be sent without body text; in this case, a short sentence with the date and time of sending is automatically added (e.g., “Mail sent at: Thu, 23 Mar 2006 02:31:44 -0800”). The address of the string can be determined with the ADR operator.

cbMessage

UDINT

The length of the email text. The length can be determined using the LEN operator.

bExecute

BOOL

A rising edge at this input activates the function block.

tTimeout

TIME

Maximum time allowed for the execution of the command.

FB_Smtp 3: Outputs

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

Name

Type

Description

bBusy

BOOL

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

BOOL

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.

nErrId

UDINT

Contains the command-specific error code of the most recently executed command (see table).

FB_Smtp 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 system type

PLC libraries to be linked

TwinCAT v3.0.0

PC or CX (x86)

Tc2_Smtp