PromaSoft AutoResponder Help
  Running External Programs
 

 

Introduction (available as of version 1.3032)

Using this feature of PSAR you are able to start an external program upon reception of an email and merge the output generated by the external program into the reply.

These programs can for instance be

  • batch files (e.g. mydir.bat)
  • executables (e.g. generate.exe)
  • and so on ...

Rather then explaining each setting seperately we will give an example on how you can use this feature

Defining the filter

Open the filter definition panel and create a new filter. Let's call it sysinfo. Fill out the details as shown in below picture

This filter will respond to incomming email with the word sysinfo in the subject line.

The [BATCH] keyword

Notice the keyword [batch] in the body of the Reply Settings. This keyword will be replaced by the output of our external program. If your external program does not generate output you don't have to use the [batch] keyword.

Specifying the external program

Now it's time to define which external program needs to be executed. Note that you can run as many external programs as you want in response to a single email. In this example we will only define one external program.

Click the forwarding and actions button

Select Other Actions and External Program

Fill out the details as seen in below picture. Important: once you filled out the details in the upper section of the panel you need to click on the Add button the add the action to the list in the bottom area of the panel. You can guess that you can 'Add' as many actions as you want to that list. In this example we'll only use on action.

Now Click Done

Command Line field

This is the exact path and file name to the external program. In our case this is a plain batch file. The contents of that batch file is as follows. Note that this is only an example. It's up to you to decide what your extarnal program does. As said before it can be whatever program (batch, perl, exe, c++, VB, VBSCRIPT, excel ...)

ECHO ======================================================= > c:\output.txt
ECHO The first word of the subject is %1 >> c:\output.txt
ECHO The system date is printed below >> c:\output.txt
date /T >> c:\output.txt
ECHO ======================================================= >> c:\output.txt

Above example batch file when run produces a file called c:\output.txt contains for example

=======================================================
The first word of the subject is Return
The system date is printed below
Tue 02/06/2001
=======================================================

Parameters field

This is a very important field as it is used to feed data to the external program. Everything enterend in the field is passed to the external program as commandline parameters. In out example we have used [subject]. PSAR will replace this keyword with the subject of the incoming email.

Let's say that the subject of the incoming email is Return Sysinfo then PSAR will eventually construct the command to be

c:\external.bat Return Sysinfo

You can not only use the [subject] keyword but all of the following keywords representing certain details out of the incoming email.

[SUBJECT]
[FROM]
[TO]
[REFERENCE]
[BODY]
[REPLIED]
[DATESENT]
[MAILER]
[ORGANIZATION]
[REPLYTO]

It's depending on what information the external program needs to function.

Wait for external program check box

The external program can be executed in two modes.

Wait

You can instruct PSAR to wait for the program to finish before continuing. This option is mandatory if you want to use output of the external program in your reply.

Don't wait

Don't select this option if you don't want PSAR to wait for the external program to finish (e.g. a batch file which archives certain directories on your harddisk).

Note: if you make PSAR wait you have to be sure that the external program finished in all circumstances. If it does not PSAR will sit there and wait until the timeout has expired. Your program most probably will not have generated output. PSAR will not replace the [batch] keyword for safety reasons.

Replace [Batch] keyword check box

If you want PSAR to replace the [batch] keyword in your reply with output of the external program you need to check this option. If you have checked the option you need to specify the file containing the output

Output field

This field needs to contain the exact path and filename of the output file of the external program. In our case that is c:\output.txt but it can be anything. Click on the ... button to select an already existing file or just enter it manually.

Stop waiting after

In most cases we can never be sure if an external program will indeed finish and allow PSAR to continue. To prevent a situation where PSAR would be blocked for ever we need to specify this parameter. If after the specified amount of time the external program does not finish, PSAR will continue. If you don't want PSAR to continue you can set this parameter to a very high value.

Note: this parameter is only in effect when the wait for external program function is checked.

The Test

Now let's see what happens. We will send a message to the autoresponder using subject Please send sysinfo.

PSAR will trap that email with the filter we defined as the subject contains the word sysinfo

PSAR will first execute the external program and will then snend a reply to the sender of the message. The reply will look as follows.

 

Using this function in combination with a formhandler

The form handler

Let's consider that your external program is expecting a neatly formed parameter. For example generate.exe john. Where does the parameter john come from? It can come from an email form we are using embeded somewhere in the body of that form. See example below

name: john
lastname: carpenter

The first thing we need to do is to extract the information from this email form into a formhandler database. We won't go into detail on how to do that here but you can check these instructions for more information on form handlers. In the end we will have a formhandler with two fields. One field is called name and the other is called lastname

Which actions need to be defined?

We will need to define two actions as a response to our email

Action 1 - A form handler action (Tab: formhandler processing)

Action 2 - Our external program action (Tab: other actions/external program)

The forwarding and actions panel will have to look something like below picture

You can clearly see that there are two actions defined (bottom part of the panel)

What will happen?

Upon reception of an email, PSAR will first perform the form handler processing and extract the two fields being name and lastname into the formhandler database called we (in this example).

Then PSAR will start the external program c:\generate.exe and will use the field name as parameter. The actually executed command will eventually look like c:\generate.exe john

Another example could be

Let's suppose that the subject of the incoming email is 'please send more info' then PSAR will execute the following command

c:\generate /john /carpenter /please send more info

Another example could be

Here the command that PSAR will execute will look like

copy carpenter.txt john.txt

NOTE: If you have defined a field in your form handler database which is the same as one of the predefined keywords you have to precede the predefined keyword with a tilde. Example: you have a field called [subject] in your database. To refer to the subject of the email you need to enter [~subject]

 

Notes

It's up to you do define what the external program is and what kind of output it produces. You can for instance let it produce HTML output for your HTML replies. You can use it to generate a registration code for programs you sell. You can use it to interogate external databases using VBscript or another language depending on information passed to it. You could simply launch a maintenance program without waiting for output. It's all up to your imagination.