Documentation

Send mail

Send e-mail - ST

Block name

SENDMAIL

ST call

PROGRAM TEST_SENDMAIL
VAR
TESTEMAIL:BOOL:=TRUE;

CHANNEL : STRING[64] := 'ALRCHANNEL';
SENDER : STRING[64] := 'INFO@DOMAT.CZ';
RECIPIENT : STRING[64] := 'SUPPORT@DOMAT.CZ';
SUBJECT : STRING[64];
MESSAGE : STRING[64];

END_VAR

IF TESTEMAIL THEN
SUBJECT := 'TEST';
MESSAGE := 'TEST EMAIL HAS BEEN SENT.';
MESSAGING.SENDMAIL(CHANNEL, SENDER, RECIPIENT, SUBJECT, MESSAGE);
TESTEMAIL := FALSE;
END_IF;

END_PROGRAM

Library

MESSAGING

Version

V1.0

Description

The function sends an e-mail in each PLC computing cycle. It is highly recommended to be used in ST code only to prevent occassional flooding of the recipient with many e-mails of the same contents. If You want to send more than one email at the time, You have to use this block multiple times or create some sort of switcher for addresses. PLC is capable of sending one email at the certain moment, so more emails needs to be sent with gaps. The gap between emails should be at least 1 second, but ideally even more.  

Inputs

Input Type Description
CHANNEL STRING_REF reference to variable with the communication connection definition (set in PLC properties, see below)
FROM STRING_REF reference to variable with e-mail address from which the mail is sent
TO STRING_REF reference to variable with the recipient's address
SUBJECT STRING_REF reference to variable with the e-mail subject
MESSAGE STRING_REF reference to variable with the e-mail body text

Outputs

Output Type Description
=> SINT Numeric status; result of the system settings check

Function

At each of the function calls, a e-mail is sent from the predefined from e-mail account to the to address. The e-mail subject is taken from the subject variable, and the e-mail body from the message variable.

The channel variable refers to the predefined communication channel. This has to be created in the PLC properties: doubleclick the PLC and select Message definition, then right-click the context menu and Add alarm channel.

Now, define the channel name which is the value of the channel variable. Then, the SMTP connection type must be defined: click to select the channel and set the SMTP server to be used for e-mail sending, and TCP port which the server uses for communication. If the server requires login, set Use login to true and then fill in the User name (most probably the e-mail address) and Password. Finally, confirm all changes by clicking OK in the red dialogue.

Note that the SMTP server must be accessible by the PLC: check default gateway settings, DNS server etc.

The output variable result indicates the result of the system settings check.

Value Description
0 OK
8 E-mail queue full
16 Unknown channel
24 Error - impossible to determine the status
other Internal error - contact Domat Control System support

This function is typically used to send alarm messages. The sending of an e-mail is launched by the alarm status appearance. See the ST call above for example.