Sample: Sent mail via PLC
A rising edge at bStart causes a mail to be sent.
The mail addresses and the SMTP server data must be adjusted beforehand. |
Program-variables
PROGRAM MAIN
VAR
fbSendMail: FB_SmtpV3;
sMessage: STRING := 'Hello Beckhoff';
bStart: BOOL;
bBusy: BOOL;
bError: BOOL;
nErrId: UDINT;
nMails: UINT;
END_VAR
Program-code
fbSendMail(sNetId:= '',
sSmtpServer:= 'mail.company.com',
sUsername:= '',
sPassword:= '',
nEncryption:= 0,
sFrom:= 'machine@company.com',
sTo:= 'service@customer.com',
sSubject:= 'Mail sent via TwinCAT SMTP',
pMessage:= ADR(sMessage),
cbMessage:= SIZEOF(sMessage),
bExecute:= bStart,
bBusy=> bBusy,
bError=> bError,
nErrId=> nErrId);
IF NOT bError AND NOT bBusy AND bStart THEN
bStart := FALSE;
END_IF
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 ) |