FB_SmtpV3_Full

FB_SmtpV3_Full 1:

This function block FB_SmtpV3_Full communicates with the TwinCAT SMTP Server via ADS. It offers very extensive email functionalities, such as prioritizing emails from the PLC. The individual parameters are explained in detail in this documentation.

FB_SmtpV3_Full 2: Inputs

VAR_INPUT
    sNetId         : T_AmsNetID;    (* AmsNetID *)
    sSmtpServer    : T_MaxString;   (* Smtp Server addres ( 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 stzring *)
    sTo            : T_MaxString;   (* To recipient string *)
    sCc            : T_MaxString;   (* Cc recipient string *)
    sBcc           : T_MaxString;   (* Bcc recipient string *)
    sDispositionNotification: T_MaxString;   (* Disposition notification recipent string *)
    sReturnReceipt  : T_MaxString;  (* Return recipent string *)
    nPriority       : UDINT;        (* Priority value *)
    nSensitivity    : UDINT;        (* Sensitivity value *)
    nPort           : UDINT;        (* Communication port *)
    nContentType    : UDINT;        (* Content type *)
    sSubject        : T_MaxString;  (* Subject string *)
    pMessage        : POINTER TO STRING;   (* Pointer to the message *)
    cbMessage       : UDINT;        (* Message lenght in byte to send *)
    sAttachments    : ARRAY [0..32] OF STRING;   (* Different attachments *)
    bExecute        : BOOL;         (* Trigger flag *)
    tTimeout        : TIME := T#20s;  (* Communication timeout *)
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 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. 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.

sDispositionNotification

T_MaxString

The email address specified here, receives a read notification from the recipients of sTo and sCc. However, the prerequisite for this is that it is also sent by the recipients.

sReturnReceipt

T_MaxString

A transmission confirmation of the sent email is sent to the email address specified here.

nPriority

UDINT

You can use this parameter to set the priority of the email:
1 = Highest
2 = not used
3 = Normal
4 = not used
5 = Lowest

nSensitivity

UDINT

You can use this parameter to set the confidentiality of the message:
0 = Private
1 = Personal
2 = Normal
3 = Confidential

nPort

UDINT

Here you can select the communication port. If you do not enter your own port, the default port 25 is used.

nContentType

UDINT

This parameter makes it possible, for example, to make HTML code, which is passed to the function block by pointer (pMessage) and size (cbMessage) of a string variable, readable in the email.

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 determined with the ADR operator.

cbMessage

UDINT

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

bExecute

ARRAY [0..32] OF STRING

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

sAttachments

BOOL

List of attachments (path and file name) to be sent.

tTimeout

TIME

The maximum time allowed to execute a command.

FB_SmtpV3_Full 3: Outputs

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

Name

Type

Description

bBusy

BOOL

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

bError

BOOL

The output 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 (see table).

FB_SmtpV3_Full 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