Java/Web Manual
  SoftPLC    Font size:      

SENDMAIL

SoftPLC provides a freely modifiable and deployable TOPDOC Loadable Instruction (TLI) that adds the ability to send email from a SoftPLC system. The TLI is Java code that gets called from Ladder, and the packaging of the TLI is in the form of a Modlet.

A similar instruction could be used to receive email as well, although that would require a development effort by somebody familiar with Java programming as well as the POP3 protocol. SendMail only supports the sending of email and not receiving.

Technical Overview

A dedicated Service Thread is started which blocks on a com.softplc.Queue. This is sort of an "outbox" for the SoftPLC. Mail messages are sent from this Queue so that the main control Thread is not involved in sending the messages. It is however, involved in formatting the text for the messages, and since this happens in the context of the Ladder Thread, this needs to be done quickly. Therefore we chose a simple fast scheme where all message text could be produced without consulting the disk.

The Service Thread is the one that interacts with the TCP/IP socket and normally runs at a priority lower than the ladder thread. It can operate on a leisurely basis since the text has already been captured in the outbox Queue by the time the message is actually sent.

Hardware Requirements

SoftPLC must be placed on an ethernet to send email.

SendMail uses the SMTP protocol over ethernet TCP/IP to send mail. SoftPLC is the SMTP client. Somewhere in the picture there must be an SMTP server. This server can be 1) in-house, or 2) at your Internet Service Provider (ISP).

When running in a SoftPLC, it is recommended that you not try and use a modem, but rather use an in-house ethernet where one of the boxes on the in-house ethernet is running an SMTP mail server program. The SMTP server will then forward the email message as needed.

  1. When using an In-House SMTP server, there are several possibilities:
    1. Any Linux machine has this capability, and most Unix boxes do too.
    2. Mercury/32 is a freeware SMTP server that can also dialout over modem to your ISP. It only runs on Windows. Information on Mercury/32 can be found in the usenet news group: bit.listserv.pmail.
    Note that having an internal SMTP server can be handy even if you have an external one as well. Departmental internal emails can be routed via this server.
  2. When using your ISP as the nearest SMTP server, then you need some connection to your ISP. If by modem, then you can use our product Gatecraft Junction (GCJ-2xx) which acts as both: a) ethernet to ppp router, and b) a dialup modem. Several SoftPLC's can share the same Gatecraft Junction (GCJ-2xx). You may not use a modem in your SoftPLC machine, the TCP/IP interface from the SoftPLC machine must be via an ethernet interface.
Note
If your SMTP server is not on your local subnet, then for each SoftPLC, you need to set "GATEWAY=" to your gateway machine in NETWORK.LST, see below.

Software Configuration

The SENDMAIL TLM is packaged for you as a downloadable set of files here. The package includes some tools for configuring the TLM, and the TLM itself which consists of a number of source files. However, you need to edit only two of them - MAILDATA.LST and MailData.java to fully configure the TLM for your application. You can use any text editor to modify the files. Detailed instructions for editing are included in the files themselves.

In brief, the steps required to configure the SENDMAIL TLM are as follows. Each step is described in more detail in this section.

  1. Edit MAILDATA.LST
  2. Edit MailData.java
  3. Run MAKEJAR.BAT
  4. Copy SENDMAIL.JAR into C:\JAR\MODLET on the SoftPLC CPU
  5. Add C:\JAR\MODLET\SENDMAIL.JAR to the end of your CLASSPATH in MODULE.LST
  6. Add the line SendMail to MODLET.LST

MAILDATA.LST

MAILDATA.LST is a simple text file that provides the information on the message recipients, your sending address, the SMTP server, and Authorization. Configuration is done by changing the following fields in the \SoftPLC\TLM\MAILDATA.LST file:

  • FromAddr
  • ServerAddr
  • AuthMethod
  • AuthID
  • AuthPasswd

MailData.java

MailData.java is a java source file. However, even non-Java programmers should be able to do the required editing of MailData.java. In this file are the message subject(s), message text(s), and attachment(s) detail for the emails you want to send. Each separate message has an index number that the Ladder instruction can be used to reference.

  • getSubject() method changes the subject for emails sent with the given msgIndex
  • getMessageBody() method changes the body for emails sent with the given msgIndex
  • getMessageAttachment() method changes any attachments for emails sent with the given msgIndex

MAKEJAR.BAT

MAKEJAR.BAT is a batch file you can run from a Windows command prompt. It invokes a supplied free Java compiler, which will compile and create a new SENDMAIL.JAR using your edited files. Unless your edits introduced Java syntax errors, you should see an updated SENDMAIL.JAR file with a current time stamp on it in your working directory.

After compiling and jarring SENDMAIL.JAR, you need to:

  1. Copy SENDMAIL.JAR into the C:\JAR\MODLET directory on the SoftPLC machine. You can use FTP or a simple COPY to the flash disk to perform this.
  2. Using TOPDOC NexGen, add C:\JAR\MODLET\SENDMAIL.JAR to the end of your CLASSPATH option in MODULE.LST, separating it from the rest of the list with a semicolon. CLASSPATH is an option to the MACHJ.TLM discussed elsewhere in this document. Send the edited MODULE.LST to the SoftPLC.
  3. Add SendMail to the MODLET.LST file, using FTP or editing the flash disk directly. When it comes to Java classnames, they are case sensitive, so you must add exactly this line to that file:
    SendMail

Authorization

The SENDMAIL TLM supports SMTP AUTH. The support consists one of the following: LOGIN or PLAIN. PLAIN is the recommended one to use when available.

Please see MAILDATA.LST for information on how to configure the TLM with authorization.

Choosing AuthMethod

Open a command prompt and type telnet [hostname] 25, which would connect on port 25 to the SMTP server [hostname]. Then type EHLO anyTestName and check for a line containing AUTH. Afterwards, you can type QUIT to terminate the connection.

If no AUTH line is found, then the server does not support or is not configured for SMTP authorization, and you should set AuthMethod to AUTH_NONE. If you do see an AUTH line, but it does not contain either LOGIN, PLAIN or ANONYMOUS, then the SENDMAIL TLM is not compatible with that server. If the line does contain one of the previously mentioned types, then use the table below to determine the proper value for AuthMethod:

AUTH LineAuthMethod
PLAINAUTH_PLAIN
LOGINAUTH_LOGIN
ANONYMOUSAUTH_NONE

Deployment

The ladder instruction shows up as "SENDMAIL" in TOPDOC. It takes two integer parameters:

dstIndexan integer which indexes into a hardcoded list of email addresses within MailData.lst
msgIndexan integer that controls which of several potential email messages to send.

The SendMail TLI is level triggered, not rising edge triggered. This means that it will send another email every time the rung containing the instruction is energized true when it is scanned. This is likely to be a problem, but one you can overcome by placing a ONS instruction in series with the SENDMAIL instruction. The ONS instruction should be just to the left of the SENDMAIL instruction. This pair of instructions will serve to make the SENDMAIL function rising edge triggered as desired.

The consequences of not using a rising edge mechanism is that you will fill up the internal queue within SendMail.java, and somebody will get 50 or so email messages all saying the same thing.