Author Topic: Sending Email via Authenticated SMTP Server  (Read 39947 times)

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3176
    • View Profile
    • Internet Programmable PLCs
Sending Email via Authenticated SMTP Server
« on: September 30, 2010, 05:33:24 PM »
All TRI-PLC with built-in Ethernet can send email via the SMTP server provided by the ISP which typically do not require authentication (since the ISP knows from the IP address whether the machine attempting to send email is one of its subscriber). However, if your ISP happens to insist on authentication before it will allow sending email via its SMTP server, then you may not be able to send email directly through this ISP.  

Fortunately, the TLServer version 3.15 software that is included in your i-TRiLOGI software package does have the option of authenticated SMTP connection, and you can route your PLC's email via the TLServer using the <REMOTEFS> tag. The following are the step by step instructions:

1. Setup Authenticated Emailing with TLServer

    * Start TLServer on the PC in which it will run 24/7.
    * Goto "Setup Emails"
    * Enter the SMTP server and port number of your outgoing mail server (default port is 25).
    * Enter the username and password for your SMTP server authentication.
    * Click on "Test" to test the settings. You will need to enter a destination Email address.
    * Close the Setup Emails window to enter the settings.
    * Contact your ISP if you don't know any of the above details. See the Setup Emails section of chapter 3 in the TL6 Programmers Reference Guide for more information.

2. Setup Port Forwarding for the Network that the PC running TLServer is on

If the TLServer is not on the same local area network as the PLC, then the TLServer must be made accessible to the Internet to receive TCP/IP request from remote PLCs in order to process email on behalf of the PLCs.

    * The network that the PLC running TLServer is connected to must have port forwarding setup so that remote clients (PLCs) can connect to TLServer.
    * You will need the IP address and port number shown on TLServer (the one you will be running 24/7)
    * Follow the instructions from the "Accessing The PLC from Internet" Section of the F-series or Nano-10 user manual (chapter 2.8 or 2.7 respectively) to setup port forwarding.
    * Contact your IT administrator if you are unsure.

3. Program a Remote PLC to Send an Email

You will need the following information in your program:

    * Internet IP address. This is provided by your ISP for the network that TLServer is running on. This is not your PLCs IP address or TLServers IP address.
    * Port number that TLServer is using. This is shown on TLServer. This is not the SMTP port number that you setup for Emails in TLServer.
    * Email address of the recipient. The sender Email address is not important but must be valid.


Use the following code in a custom function. Once the function is executed, the Email will be sent (with your specific settings of course).

PRINT #4 "<RemoteFS 192.168.1.180:9080>" 'make a remote connection to your Internet IP address.
PRINT #4 "<EMAIL recipient@email.com>" ' replace with your destination email
PRINT #4 "SENDER: sender@email.com"   ' should be a valid server address
PRINT #4 "SUBJECT: Email sent by your PLC"
PRINT #4 "I am a TRiLOGI PLC"      
PRINT #4 "This is a Hello Message"
PRINT #4 "</>"      ' end the email.
PRINT #4 "</RemoteFS>"    ' end the remote connection

Note that the IP address used in the above code should be replaced with the Internet IP address and the port should be the one used by TLServer (default is 9080). If port forwarding is setup correctly, a PLC should be able to connect remotely over the Internet using the Internet IP address of the location where TLServer is running and the port number which will be forwarded to the local IP address of the TLServer (the IP address that TLServer shows)

Also note that the above code does not do any error checking so you won't know if it is successful unless you physically see the Email. You can improve the code by adding error/status checking. You can also look at the TestEthernet.PC6 program for more examples on sending Email and making remote TLServer connections.
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3176
    • View Profile
    • Internet Programmable PLCs
Re:Sending Email via Authenticated SMTP Server
« Reply #1 on: August 05, 2011, 11:51:08 PM »
The last post shows you how to route your email via TLServer in order to satisfy SMTP authentication requirement. However, in some application it may not always be convenient to connect to TLServer to send authenticated email and there are users who prefer to send authenticated email directly from the PLC.

Although the PLC's built-in <EMAIL> tag does not handle authentication, it is possible to use the <TCPCONNECT> tag to interact directly with the SMTP server to send (non-SSL encrypted) authentication information before sending out the email. The following file contains explanation and sample programs that enables you to do so:

http://www.tri-plc.com/applications/EmailAuthentication.zip

Editor's Note: The above file has been updated on 2013-05-15.
« Last Edit: May 29, 2013, 07:23:01 AM by support »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3176
    • View Profile
    • Internet Programmable PLCs
Re:Sending Email via Authenticated SMTP Server
« Reply #2 on: September 12, 2013, 09:18:21 AM »
A new, "Email Relay Server" feature has been added to TLServer starting from version 3.17. The "Email Relay Server" feature is for the TLServer to act as a pseudo, unauthenticated S0MTP mail server to the PLCs and receive the email data from the PLC. It then in turn connects to an authenticated SMTP server and "relay" the email data to the actual SMTP server. In order to use this feature, the PLC would configure its SMTP IP address to be that of the IP address of the PC that is running the TLServer, and the SMTP port to 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). Your 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.  
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

mashuli

  • Newbie
  • Posts: 5
  • I'm a llama!
    • View Profile
Re:Sending Email via Authenticated SMTP Server
« Reply #3 on: September 16, 2013, 06:40:34 PM »
You are only focusing on sending email while running TLserver 24/7, doesn't this mean this Nano PLC can't send email using its so called "built in TLsever". I thought you could program this plc and leave it only connected to a router by ethernet cable so that it can send email by programmed events!
what a point of ethernet port if there is still a PC to run tlserver?

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3176
    • View Profile
    • Internet Programmable PLCs
Re:Sending Email via Authenticated SMTP Server
« Reply #4 on: November 27, 2013, 07:09:12 AM »
Please refer to the above threads. PLC can send email directly from its Ethernet port by connecting to the SMTP server using the <TCPCONNECT> tag and supply the username and password in Base-64 encoding.

Using the TLServer option is just an additional options that simplify programming somewhat but not the only way for the PLC to send email. In many applications there is always some PC on the LAN that runs 24/7 so in such situation using TLServer as an email relay will work perfectly. If you have having a lone PLC running at home then the option of using the <TCPCONNECT> method described in the earlier thread on this topic should work for you.
« Last Edit: November 27, 2013, 07:09:46 AM by support »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

davidg

  • Newbie
  • Posts: 11
    • View Profile
    • My Mobile HMI | Connect a mobile App to your PLC
Re:Sending Email via Authenticated SMTP Server
« Reply #5 on: June 18, 2014, 09:07:04 PM »
I just thought I would post this information in case anybody was looking for an alternative to using TlLServer or your ISP's SMTP Servers.

The information found at http://www.mymobilehmi.com/#!email-delivery-overview/c1rvg will walk you through how this works.  Email me if you have any questions.