×

Please give details of the problem

Docs

Find

SEC-SMTP Adapter

The "SMTP Adapter" is used to send emails through a local SMTP server. It requires the "Connector agent" and the "Protocol Manager" to be installed and running. Please folow the SEC - Installation Guide.

In this tutorial we assume:

  • The SEC manager is running on the server and a tunnel is open and configured (See how to install and configure the SEC).
  • The server has Java installed.
  • The ping port on the manager is 4444 (this can be configured in the adapter and the manager).
  • The manager is running on the same server as the adapter (127.0.0.1).

Install and Configure the Adapter

  • Download and unzip the SEC SMTP zip file on your local server.
  • You must navigate to [install-path]/configFiles and modify the Handler.config and the SMTP.config files.

NOTE: We recommend you install the Adapter in a "Adapters" folder inside the SEC installation path.

The Handler.config file should look like this :

1
2
3
4
5
6
7
8
    #Generic Protocol Configuration
    protocol = SMTP
    protocolClass = org.runmyprocess.sec.SMTP
    handlerHost = 127.0.0.1
    connectionPort = 5832
    managerHost = 127.0.0.1
    managerPort = 4444
    pingFrequency = 300

Where :

  • protocol is the name to identify our Adapter.
  • protocolClass is the class of the Adapter.
  • handlerHost is where the Adapter is running.
  • connectionPort is the port of the adapter where data will be received and returned.
  • managerHost is where the SEC is running.
  • managerPort is the port where the SEC is listening for ping registrations.
  • pingFrequency is the frequency in which the manager will be pinged (at least three times shorter than what's configured in the manager).

The SMTP.config file should look like this :

1
2
3
4
5
#SMTP Configuration
mail.smtp.auth=true
mail.smtp.starttls.enable=true
mail.smtp.host=smtp.gmail.com
mail.smtp.port=587

You should replace these values with your local SMTP server information.

Note: This example shows a IMAP gmail configuration. The SMTP adapter generates the email via the javaMail API with the properties configured in the configuration file. You should configure the SMTP Adapter depending on your SMTP server. You may find a reference to the available JavaMail smtps properties here.

Running and Testing the Adapter

You can now run the Adapter by executing the SMTPAdapter.jar in the install path :

1
java -jar SMTPAdapter.jar

Note: Make sure that you have launched the Protocol Manager and it is running on port 8080.

If everything is configured correctly, you can now place a request from RunMyProcess to send an email. The POST body should look like this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
{
"protocol":"SMTP",
"data":{
        "username":"blabla@blabla.com",
        "password":{
            "encoder":"None",
            "password":"myPassword"
        },
        "from":"blabla@bla.com",
        "to":"blabla@bla.com",
        "subject":"HELLO",
        "body":"WORLD",
        "attachedFiles":[
            {
            "name"="BLA.ext",
            "data"="SOME BASE 64 DATA" 
            },
            {
            "name"="BLA2.ext",
            "data"="SOME OTHER BASE 64 DATA" 
            }
        ]
    } 
}

The password can be encoded in base64 by assigning "base64" to "encoder" in the "password" object and sending the password as base64.

The expected return is a JSON object that should look like this :

1
2
3
4
{
"SECStatus":200,
"Message":"Mail Sent!"
}

Automatic launching.

In order to access adapter resources from RunMyProcess, the Connector Agent, Protocol Manager and the required adapters must be running. You can create a script (shell script or bat file) to launch all resources. For example, in windows, you can create a bat file that looks like this:

1
2
3
4
5
6
7
@echo off
cd %SECPATH%\data-connector-agent\bin
call start "Tunnel" runagent.bat
cd %SECPATH%\jetty7.6.11
start "Manager" java -jar start.jar
cd %SECPATH%\Adapters\SMTPAdapter
start "SMTPAdapter" java -jar SMTPAdapter.jar

Note: for the example presented note that the %SECPATH% environment variable should point to the installation path of the SEC. Also note that the Adapter is inside an "Adapters" folder in the SEC installation path. We recommend you follow this best practice.