Example: Using the Mail Service SL Library
Product: CODESYS IIOT Libraries SL
The example show how to send, receive, and delete emails on a CODESYS controller.
Description
The Mail Service SL Example.project
sample project shows how to use the function blocks. A simple email client with visualization is implemented in the project.
Functionality
Button: Settings
Change the POP3 login here, as well as the SMTP/POP3 server addresses and ports.
With Use TLS, an encrypted connection is established to the server (SMTPS).
Button: New Message
In the page bar, click New Message to write a new mail. Add the sender, recipient, subject, and a message text to the mail in the respective fields.
To send files, specify the full file path (for example: "C:/temp/testfile.txt"). Click Send to send the email.
Button: Get first email
When you switch to the Inbox in the page bar, the mail program automatically checks whether or not new emails have arrived on the server.
Click Refresh to manually fetch new emails. After receiving the email, you can click Delete to delete the email and fetch the next unread email on the server.
Area: Errors
Error messages are displayed in the lower area of the page bar.
Technical functions
This mail program runs through seven different states: FIRST_START
, INIT_SERVER
, SEND_MAIL
, NEW_MAIL
, RECEIVE_MAIL
, DELETE_MAIL
, and WAITING
.
As a result of an input in MainVisu_PRG
, the Mail ServiceSL
switches to another state (for example, SEND_MAIL
). Then the program remains in this state until the condition is fulfilled for switching to another state. For example, when an email is sent, the program switches to the WAITING
state afterwards. It remains there until another state change is triggered.
MAIL_PRG
: This main program runs through the following seven states:
FIRST_START
This state becomes active when starting the program. All settings here are assigned with default values. Server addresses and ports are assigned, and memory is reserved for receiving emails.
INIT_SERVER
Initializes the server with new values (for example, user name and password or other server addresses and ports).
SEND_MAIL
In this state, an instance of
EMAIL_SEND
is sent via SMTP by an instance ofSERVER
.NEW_MAIL
The values of the current instance of
EMAIL_SEND
are reset here and theSENDMAIL VISU
visualization is prepared for sending a new email.RECEIVE_MAIL
The program fetches new email from the server via POP3. If an unread email exists, then this is saved in
EMAIL_RECV
.DELETE_MAIL
In this state, the currently displayed email is deleted from the server. This is done by means of the message ID. For
DELETE_MAIL
, the server has to support mail IDs.WAITING
Nothing happens here. The program simply remains in this state and waits for input from the visualization.
System requirements and restrictions
Programming system | CODESYS Development System (version 3.5.18.0 or higher) |
Runtime system | CODESYS Control Win (version 3.5.18.0) |
Additional requirements |
|
Restrictions | The maximum size of an email (maximum size of the send/receive buffer) is limited to 32,767 bytes. |
Note
DOWNLOAD projects