Invoking a Web Service via Email

Version: 17.07

Supported Since: 17.01

Use Case Description

I have an integer multiplication web service exposed over HTTP, and want to make it accessible via email, where emails containing the input data sent to a predefined address are processed and replied to with the multiplication results.

Solution

UltraESB-X can be configured to proxy messages between the email service and the web service in order to enable the acceptance of data from and propagation of results to email senders.

UltraStudio Configuration

UltraESB-X Configuration

Implementation of the Solution

Prerequisite

In order to implement above use case you must first select following dependencies when you are creating a new Ultra project.

  • Mail Connector from the connector list

  • NIO HTTP Connector from the connector list

  • Transport Header Manager from processor list

If you have already created a project, you can add above dependencies via Component Registry. From Tools menu, select Ultra Studio → Component Registry and from the Connectors list and Processors list, select above dependencies.
Implementation

To implement above use case, first create an integration flow named “web-service-via-email-flow”, and then add required components by going through following steps in order.

  1. Add a Mail Ingress Connector from the Connectors → Ingress Connectors list, to accept incoming multiplication request emails, with the configuration shown below (assuming a Gmail account)

  2. Add an Add Variable processing element from the Processors → Generic list, to extract the value of the retained From header (sender’s email address) into a recipient variable

  3. Add a NIO HTTP Egress Connector from the Connectors → Ingress Connectors list, to forward the received request to the multiplication web service

  4. Add an Add New Transport Header processing element from the Processors → Header Manipulation list, to set the subject of the response email

  5. Restore the previously saved sender’s email address from recipient variable into the mail.to transport header, using another Add New Transport Header processing element

  6. Add a Mail Egress Connector to send the response back to the sender (assuming a Gmail account)

  7. Finally add a Successful Flow End processing element to complete the flow

The completed integration flow should look like below.

web service via email component complete flow

Configuration for each element is as below. The numbering corresponds to the numbers shown in above diagram.

Design View

Text View

.

1. Mail Ingress Connector (Basic Tab)

web service via email component 1

For other settings, specify below Map entries

web service via email component pop map

1. Mail Ingress Connector (Processing Tab)

web service via email component 1 1

1. Mail Ingress Connector (Scheduling Tab)

web service via email component 1 2

2. Add Variable

web service via email component 2

3. NIO HTTP Egress Connector

web service via email component 3

4. Add New Transport Header

web service via email component 4

5. Add New Transport Header

web service via email component 5

6. Mail Egress Connector

web service via email component 6

For other settings, specify below Map entries

web service via email component pop map
.

1. Mail Ingress Connector (Basic Tab)

Protocol

imap

Host

imap.gmail.com

Port

993

User

Password

your-password

Folder

INBOX

Other Settings

mail.imap.ssl.enable → true

mail.smtp.starttls.enable → true

1. Mail Ingress Connector (Processing Tab)

Preserve Headers

From

Lazy-fetch Payload

Off

Lazy-fetch Attachments

On

1. Mail Ingress Connector (Scheduling Tab)

Polling Start Delay

2000

Polling Repeat Interval

10000

2. Add Variable

Variable Name

recipient

Extraction Type

HEADER

Value

From

Variable Type

String

3. NIO HTTP Egress Connector

Destination Address type

URL

Destination Host

localhost

Destination Port

9000

Service Path

/service/JsonServlet

4. Add New Transport Header

Transport Header Name

mail.subject

Use Variable

Off

Value

Multiplication Result

Header Variable Type

String

5. Add New Transport Header

Transport Header Name

mail.to

Use Variable

On

Value

recipient

Header Variable Type

String

6. Mail Egress Connector

Protocol

smtp

Host

smtp.gmail.com

Port

25

User

Password

your-password

Other Settings

mail.imap.ssl.enable → true

mail.smtp.starttls.enable → true

.

Now you can run the Ultra Project and check the functionality of the integration flow. Create an UltraESB Server run configuration and start it.

Property Configuration

When running the sample in the UltraESB-X distribution, you need to override the following properties in-order for the sample to work. The properties file is located at $ULTRA_HOME/conf/projects/web-service-via-email/default.properties

Refer to Managing Project Properties documentation on how to override properties.

web-service-via-email-flow.email-listener.user

Email account of the user who accepts input data

web-service-via-email-flow.email-listener.password

Email password of the user who accepts input data

web-service-via-email-flow.email-sender.user

Email account of the user who sends back computed data

web-service-via-email-flow.email-sender.password

Email password of the user who sends back computed data

After that navigate to $ULTRA_HOME/bin directory. Next you can run the UltraESB-X distribution with following command to start the engine with this sample project deployed.

./ultraesbx.sh -sample web-service-via-email

Testing the Integration Project

  • A multiplication service that accepts JSON payloads in the format {"v1":first_number,"v2":second_number} is available in the Jetty Server plugin shipped with Ultra Studio. Click View → Tool Windows → Jetty Server and click the green start button to start a Jetty server at port 9000. (If you have run a server instance previously, it will be listed in the Jetty Servers list, in which case you should start the corresponding (port 9000) server from the list.)

  • Send an email to your-email@gmail.com containing a multiplication request in the message body, such as the following: {"v1":7,"v2":6}

  • A response email will be delivered to the account from which you sent the multiplication request, resembling: {"result":42,"v1":7,"v2":6}

Depnding on the email provider which hosts the emails that you have mentioned above, you may have to enable insecure application access in account settings
In this topic
In this topic
Contact Us