MASTER YOUR CASTLE with your new build or reno project
Enter competition

M340 Email



Goals and Symptoms

Sending an Email from the embedded Ethernet port on a M340 CPU.

Facts and Changes

The send Email function can only be used on the Embedded Ethernet port of the M340 CPU modules.
The M340 need to be v2.0 or higher and minimum version of Unity Pro v4.0 must be used.
In this example a free SMTP utility known as Argosoft is used as the email server.
In an actual application special considerations need to be taken on the SMTP server or the Send Email function will not work.

Causes and Fixes

In your Unity Pro application open you Ethernet network. Confirm that the network is configured for a M340 v2.0 CPU and the SMTP is activated.
Click on the SMTP tab.

Fill in the IP address of your SMTP server and choose the port it is listening on (port 25 is the default)
Fill in the Mail Header information for the email you will be sending.
The M340 will allow you to have 3 different mail headers which means you can send up to 3 emails.

Note: The maximum size of the email message is 1k which includes the email header.


If your Email SMTP server requires a login and password then this will need to be enable in the SMTP setup.

Validate your changes then open the project setting under Tools>Project settings

In the project settings under language extensions make sure all data types are checked then press ok.
This will allow for arrays to directly be used in the program.

In your Unity Pro program add a ADDM and SEND_EMAIL function block.
Make sure EN/ENO is displayed.

To send an email the input to the ADDM will always be a string input '0.0.3' which tells the M340 to use the embedded Ethernet port.
The HEAD_KEY chooses which Mail Header to use from the SMTP setup.
If the subject is listed in the Mail Header then the SUBJ_STR can be left blank. Otherwise you will need to put a string input here to be the Email subject.
The BODY_STR is a string input which will serve as the body of the email. The entire Email cannot be greater than 1k in size.
The GEST is a array of 4 words which serves as the Management parameters for the SEND_EMAIL function block. (see Unity help files for more information)

In this example whenever %M0 is high the M340 will send an email to the destination listed in Mail Header 1.

You can launch a animation table an confirm the email is being sent out by looking at the first word of the GEST parameter when %M0 is high.
If this value is changing and there is no error code in word 2 then the email is being sent out.

This only indicates that the M340 sent the message and does not guarantee that the message was received.
The M340 is only capable of composing an email and pushing it to the SMTP server.
It is up to the SMTP server to properly deliver the message to its destination.

If there are no errors then log into you email sever and confirm the message was delivered.

Open new mail

Read the message.

Considerations to be done outside the M340

In this example a simple SMTP server (Argosoft) was used to demonstrate the ability to have the M340 send an email.
In a real world application the M340 will need to be on the customers domain.
Also the SMTP server that the M340 points to needs to be able to accept the message directly from the M340 and route it accordingly.
If the SMTP server is not configured to do this then the M340 email will not be processed.