FB_SmtpFull

FB_SmtpFull 1:

This function block communicates over ADS with the TwinCAT SMTP Server. It offers a wide range of mail functionalities as for example the prioritization of emails out of the PLC. The individual parameters will be described in detail in this documentation.

VAR_INPUT

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 *)
    nAuth                   : UDINT;         (* Smtp Auth Type*)
    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                : DWORD;           (* Pointer to the message *)
    cbMessage               : UDINT;           (* Messagelenght in byte to send *)
    sAttachments            : ARRAY [0..32] OF STRING;    (* Different attachments *)
    bExecute                : BOOL;            (* Trigger flag *)
    tTimeout                : TIME := T#20s;          (* Communication timeout *)
END_VAR

sNetId: AmsNetID on which the TwinCAT SMTP server runs.

sSmtpServer: Name or IP of the SMTP server.

sUsername: Username for the SMTP server.

sPassword: Password for the SMTP server.

nAuth: Smtp Auth Type:
0 = AUTH NONE
1 = RESERVED
2 = AUTH LOGIN
3 = AUTH NTLM
4 = AUTH PLAIN

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

sTo: A string containing the email address of the recipient. Several addresses can be specified, separated by semicolon. At least one recipient has to be specified. The string is limited to 255 characters.

sCc: 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: 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.

sDispositionNotification: The mail address which is given to this parameter receives an return receipt of the recipients under sTo and sCc. The condition precedent is that the return receipt will be send by the recipients.

sReturnReceipt: An acknowledgment of transfer will be send to this mail address.

nPriority: With this parameter you can set the priority of the mail:
1 = Highest
2 = not used
3 = Normal
4 = not used
5 = Lowest

nSensitivity: With this parameter you can set the confidentiality of the message:
0 = Private
1 = Personal
2 = Normal
3 = Confidential

nPort: You can choose the communication-port here. If you do not enter an own port it will be accessed to the default-port 25.

nContentType: With this parameter it is possible to make a HTML-code which is given per pointer (pMessage) and size (cbMessage) to a string variable readable in the mail.

sSubject: A string containing the subject line for the e-mail. The email may be sent without subject, in which case the name of the sending computer is 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: The address (a pointer) to a null-terminated string containing the email text. The email may be sent without body text, in which case the date and time are entered automatically (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: Length of the email text. The length can be determined through the LEN operator.

bExecute: The function block is activated by a rising edge at this input.

sAttachments: Array of filenames

tTimeout: Maximum time allowed for the execution of the command.

VAR_OUTPUT

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

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

bError : 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 iErrorId.

nErrId: contains the command-specific error code of the most recently executed command (see table).

FB_SmtpFull 2:
  • Make sure that you do not use \o within the byte-arrays, otherwise the message will be stopped.
  • The maximum number of characters in a message is 510,725 - in total you have 1275 characters for From, To, Cc, Bcc and Subject.

Requirements

Development environment

Target system type

PLC libraries to be linked

TwinCAT v2.10. and above

 

TcSmtp.lib