Setting Up TLServer Email Functions


1. Introduction

Before the Ethernet port was integrated into the newer Super PLCs such as the Nano-10, FMD and F-series, TRi PLCs could only use the TLServer as a TCP/IP gateway to perform network related functions, including sending of emails. For newer PLCs with built-in Ethernet, in many cases the PLC can be setup to send email directly without relying on the TLServer. However, TLServer can still be very useful as email helper in the following situations:

1) There is no Ethernet cable available to the PLC but the PLC are networked via RS485 to a PC.
2) The PLCs are not permitted to make TCP connection directly to SMTP server residing outside of the LAN.
3) The SMTP server requires authentication and/or encrpytion to send email that the PLC cannot handle natively.

The following describe in details the several ways in which the TLServer can be used to help the PLC send out emails.

Email Method 1 - Using TLServer as Email Relay Server

Since version 3.20, the TLServer can be setup to work with SMTP servers that require authentication and encryption based on either startTLS or SSL/TLS. However, the default email function on the Nano-10, FMD and F-series PLCs does not support account authentication to communicate with the external SMTP server. If the PLC is connecting to the SMTP server provided by the ISP then in some cases authentication is not needed since the ISP will only allows connection from IP address that belongs to its subscribers.  

However, most SMTP Servers now require both authentication and encryption. In such a case the simple <EMAIL> tag method described on the PLC's manual will not work since the PLC does not handle authentication with the SMTP server.

It is possible to program the PLC to handle unencrypted authentication with the SMTP server using complex TBASIC statements in order to send email (see examples described on the forum under "Frequently Asked Questions"). However, to simplify programming effort, we have introduced a new, "Email Relay Server" feature to TLServer starting from version 3.17 and improved with version 3.20. The "Email Relay Server" feature is for the TLServer to act as a pseudo, unauthenticated SMTP mail server to the PLCs and receive the email data from the PLC. It then in turn connects to an authenticated SMTP server and "relays" the email data to the actual SMTP server. In order to use this feature, the PLC would be configured such that its SMTP IP address is the IP address of the PC that is running the TLServer, and the SMTP port is that of the "Port # to Relay PLC Email".

The Email Relay Server can be any PC on your LAN that runs the TLServer that is already configured to work with an external SMTP mail server (whether autheticated or not). All PLCs on the same LAN can then send their email via this TLServer instead of directly to the external SMTP server. This could be advantages in terms of ease of programming and also should the company decide to change its ISP or SMTP server provider, only the TLServer needs to be re-configured and the PLCs on the network need not be configured individually to address the change. 

Once the Email Relay Server is configured in both TLServer and the PLC, the standard way to send emails from the PLC using the PRINT#4 command and the <EMAIL> tag can be used directly as before. This is Email Method 2 described next.

Email Method 2 - Using TLServer as Email Slave

In this setup, the PLC connects to TLServer, which will monitor the data it receives via its serial port for a special <EMAIL> tag. This triggers a sequence of actions where TLServer receives the sender, recipient, subject and mail content via the serial port or Ethernet. When all the data has been received the TLServer will connect to the SMTP server and send out the email. For more details on this email method,  please click here to go view File and Email Services.

NOTE: For Super PLCs with built in Ethernet, it is recommended to setup the TLServer as an Email Server Relay (method 1 above) so that the PLC does not need to be programmed to connect to TLServer and use the Email services.

Email Method 3 - Using TLServer as Email Master (Legacy)

The TLServer supports a legacy email feature (carried over since version 1.0) where the TLServer act as a master to a bunch of PLCs connected together via their RS485 port. TLServer can be configured to scan the internal variables of any of the up to 256 PLCs ID connected to it to determine if any of these PLCs has a request for the TLServer to send out email. If so the TLServer will then retrieve the email data from the relevant PLC, constructs a complete email and send it out.   Click here for more details.

 


2. Configure, Test, and Operate SMTP EMail Server

NEW!: TLServer version 3.20 offers a slightly new look to the Email Setup, which has all the same features as before plus an option for encryption (select startTLS or SSL/TLS). The legacy method of sending Emails is also hidden by default, but can be accessed by selecting the "Use Lecacy Email Feature" box.

Configure

To setup the server to handle email requests, click on the "Setup Emails" button on the TLServer to open the following dialog box:

 
  • SMTP Mail Server: This will be the same Outgoing Mail Server that you use in your email program such as the Eudora or Outlook Express. If in doubt, ask your ISP or System Administrator for help. This server must be setup properly before the TLServer can send any email.
  • SMTP Port No.: This is the port that your Outgoing Mail Server will use to send emails. The default port number is 25, which is the most common port; however, some Mail Servers will use a different port and you should check with your ISP or System Administrator if you are not sure.
  • Authentication: Some ISPs will only allow mail to be sent through their Mail Server if it originates from a trusted IP address (typically, only the Internet IP address that the ISP assigns to you). If this is the case, then you may need to authenticate your IP address if it is different from the one provided to you (If you are sending mail from a location registered to another ISP using your Mail Server). If your ISP uses Authentication, then you will need to check the Authentication box and provide the correct Auth. Username and Auth. Password. If you are unsure about this, then you should contact your ISP or System Administrator for help.
  • Auth. Username: If Authentication is required, you will need to provide the correct Username. This is provided by your ISP and you should contact your ISP or System Administrator if you don't know what it is or if you don't know if you need it.
  • Auth. Password: If Authentication is required, you will need to provide the correct Password. This is provided by your ISP and you should contact your ISP or System Administrator if you don't know what it is or if you don't know if you need it.

  • Use Encryption: If encryption is required, you simply check the box to use encryption and then select the type of encryption utilized by your SMTP server. For example, in order to use Gmails SMTP server on port 587, it is recommended to use startTLS encryption (requires setting Gmail to allow access from less secure apps).

  • startTLS: Upgrades an insecure connection to a secure one using TLS or SSL (depending on server requirements). Check with your Email service provider if this the correct option.

  • SSL/TLS: Uses TLS or SSL encryption (depending on server requirements) over a secure connection. Check with your Email service provider if this the correct option.
  • Port # to Relay PLC Email:  If the TLServer is setup to be the email relay server for the PLCs,  TLServer will be listening on this port for a SMTP connection from the PLC. The default port number is 9025.  This port number is to be used as the SMTP port # on the PLC's "Ethernet & ADC Configuration" screen in order for the TLServer to relay the email content to the actual SMTP server that requires authentication.

  • Email Test: Refer to the section Test the Email Configuration below.

  • emailsetup8.jpg (1789 bytes) If you use the TLServer email relay feature and encounter failure when the PLC attempts to email and if you cannot figure out what caused the problems, then you can start up the TLServer with Java Console enabled and re-run the email test with the "Debug" checkbox selected. The Java console will output all interactive messages the TLServer exchanges with the SMTP server. From the error messages produced you may be able to better figure out the cause of the email failure.

    Note: TLServer automatically enables debug messages when you use the "Email Test" button to send a test email via the SMTP server, regardless of the state of the "Debug" checkbox. The "Debug" checkbox is effective only when TLServer carries out the the email relay operations on behalf of the PLCs.  

________________________________________________________________________________________________________
Important
: your PC's firewall must be setup to allow connection to this port  from other devices on your network in order for TLServer to work as an email relay server for the PLC.
________________________________________________________________________________________________________

Example

If the PC running the TLServer has IP address = 192.168.1.100, and the "Port # to Relay PLC Email" is set to 9025, then if the PLC wants to use TLServer as a SMTP relay server, its Ethernet port settings should be configured as shown below:

1) Open the ADC & Ethernet Configuration tool from the Controller menu in TRiLOGI.

2) Assuming the network settings are already properly setup for Ethernet communication, only the SMTP server IP and port number need to be set. For this example, the SMTP server IP is set to 192.168.1.100 and the SMTP port number is set to 9025 to match theEmail server relay port number configured in TLServer-->Setup Emails

emailsetup2.jpg (27197 bytes)

Test the Email Configuration

emailsetup4.jpg (1756 bytes)

You can test your email configuration by clicking the  button once you have entered all the correct settings. Once you click the "Email Test" button TLServer will initiate the sending of a test email using the Mail Server you specified. A new window will pop up, as shown below, that allows you to enter the recipient email address.

emailsetup5.jpg (11165 bytes)

Once you have typed the recipients email address, you can press enter to send a default email (can't be changed). If it works, you will see a message window that says the email has been sent, as shown below, and you will receive an email with the following content: "Test Message sent from TLServer"

emailsetup7.jpg (12697 bytes)

If some settings in the email configuration are not correct or you do not have a working Internet connection, you will see an error message.

 

Operate with PLC

Super PLCs implement a list of "Network Services" (NS) commands similar to what you may have read in the TLServer (Files and Email Services).

The Email NS command begins with a string enclosed within the angle bracket called a "tag", which is <EMAIL> in this case, and ends with a closing tag "</>". Depending on the command type, the PLC CPU may return one or more response strings via virtual comm. port #4, from which the PLC can read to determine if the NS command has been executed properly. The PLC can operate the Ethernet port by means of TBASIC INPUT$ and PRINT commands operating on COMM 4. It uses the PRINT #4 command to send out NS commands and the INPUT$(4) command to receive response data via the Ethernet port.

E.g. To send data to an email address: whoever@yahoo.com with the subject "PLC Email Test", execute the following statements in a TBASIC custom function:

PRINT #4 "<EMAIL whoever@yahoo.com>" ' change it to your own email.
PRINT #4 "Sender: triuser@hotmail.com" ' it can be anything.
PRINT #4 "Subject: PLC Email Test"
PRINT #4 "Hello, this email is sent by your friendly i-TRiLOGI PLC"
PRINT #4 "Don't worry, everyting is working out great today!"
PRINT #4 "</>"

FOR I = 1 to 10000
  A$ = INPUT$(4)
' read response provided by TLServer
  IF LEN(A$) <> 0 EXIT: ENDIF
NEXT

Note:

  • "Sender:" field should be in email format e.g. xxx@yyy.zzz, but it does not need be an actual valid email address.
  • "Subject:"  field is optional and may be omitted totally
  • Once the TLServer receives the end-of-service tag "</>" from the PLC and it will then send out the email to the recipient email address. This email service will make use of the SMTP Relay server, which is configured as described above.
  • When the email has been successfully sent via the SMTP server, the TLServer will send an "<OK>" tag to the PLC to acknowledge that the Email request has been successfully completed. It is up to your PLC program to check for the "<OK>" tag to determine if it the service it requested has been processed.

SENDING EMAIL FAILS

If you receive an error message instead of "<OK>" or the email is not delivered, then it could have been blocked by Java security or other antivirus/firewall software.

Run TLServer with a Java Console (this can be done by running TLServer32.bat).

You may get a prompt from Java security, Windows, or other Internet security management software asking if you want to block or allow the application and of course select allow for all network types.

Check the debug option in TLServer-->Setup Emails (Refer to the end of the configuration section)

Now try sending the email again and monitor the console for details.

If the email is still blocked, then you may need to manually add TLServer to the allowed list for the software blocking it. Perform an Internet search for instructions on adding a program to the allowed list for the software in question since every security software has its own procedure.