SmtpFull sample with features
With the FB_SmtpFull very extensive email functionalities are available for the PLC.
Description
These possibilities are shown in the sample:
- Among other things, the email text is transferred in HTML code, which offers completely new formatting possibilities.
- Furthermore, the priority of an email can now be set or read receipts can be requested.
- Multiple files can be sent as attachments.
An email is sent after triggering the variable bStart.
ToDo: configure the mail server address, the credentials and the paths to the file attachments.
Program variables
VAR
fbSmtpFull : FB_SmtpV3_Full;
sMessage_HTML : STRING(500) := '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><title>HTML-Test</title><body><h3>Dear SMTP-User,</h3>this e-mail was sent in HTML from <u>your PLC!</u><br/><br/>Best regards,<br/>your Beckhoff-Team</body></html>';
nPriority : UDINT;
R_Edge : R_TRIG;
bStart : BOOL;
bError : BOOL;
udErrId : UDINT;
nMailCounter : UDINT := 0;
sFiles : ARRAY [0..32] OF STRING(80) := ['c:\Temperatures.txt','c:\Log.txt']; (* TODO: Adjust file paths*)END_VAR
Program code
fbSmtpFull(
sNetId:= '',
sSmtpServer:= 'mail.company.com',
sUsername:= 'TestUser',
sPassword:= 'TestPwd',
sFrom:= 'TestUser@company.com',
sTo:= 'service@company.com',
sSubject:= 'Email from your Beckhoff PLC',
nContentType:= 2, (* 2 = HTML *)
nPriority:= 1, (* 1 = HIGH *)
sAttachments:= sFiles,
pMessage:= ADR(sMessage_HTML),
cbMessage:= SIZEOF(sMessage_HTML),
bExecute:= bStart,
bError=> bError,
bBusy=>bBusy,
nErrId=> nErrId);
IF NOT bBusy AND NOT bError AND bStart THEN
nState := 0;
bStart := FALSE;
END_IF
Requirements
Development environment |
Target system type |
PLC libraries to be linked |
---|---|---|
TwinCAT v3.0.0 |
PC or CX (x86) |
Tc2_Smtp |