×

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.

The following is assumed :

  • The SEC manager is running on the server and a tunnel is open and configured. You can find instructions on how to install and configure the SEC here.
  • 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).
  • The Unified Adapters zip file has been extracted to your local server as described here.

1 Configure the Adapter

The Adapter is configured by modifying the handler.config and by creating a SMTP.config file in the [SEC-PATH]\configFiles folder. A reference configuration file can be found in the \configFiles\smtp.reference folder.

NB: It is recommended that the Adapter be installed 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 an 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.

2 Running and Testing the Adapter

You can now run the Adapter as follows:

On Windows:

1
runAdapter.bat

On Unix:

1
java -jar unified-adapter_${version}.jar

or (recommended):

1
java -server -Xmx512m -Xss256m -Djava.util.logging.config.file=./log.properties -jar unified-adapter_${version}.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 value is a JSON object that should look like this :

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

3 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%\sec-agent-manzanillo\bin
call start "Tunnel" runagent.bat
cd %SECPATH%\jetty7.6.11
start "Manager" java -jar start.jar
cd %SECPATH%\Adapters\SMTP
start "SMTPAdapter" java -jar unified-adapter_${version}.jar

Where version is the current unified adapter version installed on your server.

Note: For the above example, note that the %SECPATH% environment variable points to the installation path of the SEC. Also note that the Adapter is inside an Adapters folder in the SEC installation folder. We recommend you follow this best practice.