Sample: Sending of HTML mails
With the FB_SmtpV3Full very extensive email functionalities are available for the PLC. Among other things, the email text is transferred in HTML code, which offers completely new formatting possibilities. This makes it very easy to transfer current measured values or similar in a structured form.
Download: Sample02_Send_Html.zip
The mail addresses and the SMTP server data must be adjusted beforehand. |
Program variables
PROGRAM MAIN
VAR
fbSmtpFull : FB_SmtpV3_Full;
sMessage_HTML : STRING := '<!DOCTYPE html><html><body><p>Sent by TwinCAT SMTP.</p></body></html>';
bStart: BOOL;
bBusy: BOOL;
bError: BOOL;
nErrId: UDINT;
END_VAR
Program code
fbSmtpFull(
sNetId:= '',
sSmtpServer:= 'mail.company.com',
sUsername:= '',
sPassword:= '',
sFrom:= 'machine@company.com',
sTo:= 'service@customer.com',
nContentType:= 2,
sSubject:= 'Email from your Beckhoff PLC',
pMessage:= ADR(sMessage_HTML),
cbMessage:= SIZEOF(sMessage_HTML),
bExecute:= bStart,
bBusy=> bBusy,
bError=> bError,
nErrId=> nErrId);
IF NOT bError AND NOT bBusy AND bStart THEN
bStart := FALSE;
END_IF
Requirements
Requirements
Development environment | Target system | PLC libraries to include |
---|---|---|
TwinCAT v2.10.0 or higher with (x86) | x86 or ARM | TcSmtp.Lib ( Standard.Lib; TcBase.Lib; TcSystem.Lib will be included automatically ) |