Beckhoff#TwinCAT3 TF6350 Send Email From Outlook

In this tutorial I will show you how to use Beckhoff TwinCAT6350 to send an email to Outlook server.

Installation

Please access this link and Download the install packages,

https://www.beckhoff.com/en-en/products/automation/twincat/tfxxxx-twincat-3-functions/tf6xxx-tc3-connectivity/tf6350.html

Next>.

Accept the license and Next>.

Enter your User information and Next>.

Choose Complete and Next>.

Next>.

Press Install to start your installation.

Please wait a mins..

Done!

You can see a folder named “TF6350-SMS-SMTP” in TwinCAT/Functions.

System Requirment

Configure Your Email

Outlook

Outlook is used here.Login to your Outlook account and press the Gear icon.

Press the Button that Red Rectangle is pointed to.

Go to Settings>Main>Sync email.

Choose Pop options to Yes and you will see the SMTP Settings Field in the bottom.

Here is the setting of the connection to SMTP Server.

Please reference this link to get more information for the setting.

https://www.gmass.co/blog/outlook-smtp/


Why not Use Gmail?

From 2022-5-30, GMAIL is not allowed to use Less secure apps to connect to their Mail Server.

https://support.google.com/accounts/answer/6010255?hl=en

Configuration

Here is the Configuration in this tutorial. We are just using TwinCAT3 TF6350 to send an email from our Email account to another email account.


Function Block

I will only explain the Function Block that is used in this tutorial.

FB_SmtpV3

In this Tutorial, FB_SMTPV3 is used.

VAR_INPUT

sNetId T_AmsNetIDTwinCAT SMTP Server’s AmsNetID
sSmtpServer T_MaxStringSMTP Server/IP
sUsername T_MaxStringSMTP Server’s UserNameIn this case, it is your user name of the outlook account.e
sPasswordT_MaxStringSMTP Server’s PasswordIn this case, it is your password of the outlook account.e
nEncryption UDINT0=NONE, 1=STARTTLS, 2=SSL
sFrom T_MaxStringThe Sender Email Address,In this case, it is your Outlook address.
sTo T_MaxStringThe Receiver Email Address,You need to configure at least one Receiver..
sCc T_MaxStringThe CC Receiver Email Address
sBcc T_MaxStringThe Bcc Receiver Email Address
sSubject T_MaxStringThe Subject of your mail
pMessage POINTER TO STRINGThe Memory address of your Mail Content VariableExampleMail send at Thu, 23 Mar 200602:31:44 -0800
cbMessage UDINTThe Size of the your mail Content, Count by bytes
bExecute BOOLExecute by Rise Edge
tTimeout TIME := T#20sTimeout 設定

VAR_OUTPUT

bBusy BOOLTrue=Executing
bError BOOLTrue=Function Block Error
nErrId UDINTError Information

Implementation

Now we will start to make a simple program.

VAR

Variables used in our program are defined in the VAR area.

Message is the content of your email.

PROGRAM MAIN
VAR
SmtpV3:FB_SmtpV3;
Message:STRING;
bSend:BOOL;
END_VAR

PROGRAM

Please set the nEncryption=1.It is because STARTTLS is used in the Outlook SMTP Setting.

For the sFrom parameter,you only need to enter your outlook address.and the Function Block will execute while bSend is True.

Message:=’Hello! this is a test!’;

SmtpV3(
sSmtpServer:=’smtp.office365.com’
,sUsername:=’YourOutlookAccount_Username’
,sPassword:=’YourOutlookAccount_Password’
,nEncryption:=1
,sFrom:=’YourOutlook_Email’
,sTo:=’The receiver’
,sSubject:=’Test subject’
,pMessage:=ADR(Message)
,cbMessage:=SIZEOF(Message)
,bExecute:=bSend
);

IF bSend AND NOT SmtpV3.bBusy THEN
bSend:=FALSE;
END_IF

Result

You can receive the email 🙂

Sample Code

https://github.com/soup01Threes/TwinCAT3/blob/main/TwinCAT%20Project_SmtpV3_Sample.tnzip

Summary

Finally, when I was looking for information to send to Gmail or Outlook on the Internet, there are so many websites that are roughly similar. But these sites haven’t touched any settings on the Gmail side or the Outlook side. I felt a little irresponsible there. If it’s a memo blog, it’s still good, but if it’s obviously a tutorial-based site, It should be more detailed.

My goal is to make it easy for all readers.

Footer_Basic

Please Support some devices for my blog

Amazon Gift List

Find ME

Twitter:@3threes2
Email:soup01threes*gmail.com (* to @)
YoutubeChannel:https://www.youtube.com/channel/UCQ3CHGAIXZAbeOC_9mjQiWQ

シェアする

  • このエントリーをはてなブックマークに追加

フォローする