This documentation is for WSO2 Enterprise Integrator version 6.3.0 . View documentation for the latest release in the 6.x.x family and the latest release in the 7.x.x family.

All docs This doc
Skip to end of metadata
Go to start of metadata

In this tutorial, you use the Gmail connector to send an email containing the response received from SettlePaymentEP in the previous tutorial.

See the following topics for a description of the concepts that you need to know when creating ESB artifacts:

Before you begin,

  1. Download the product installer from here, and run the installer.
    Let's call the installation location of your product the <EI_HOME> directory.

    Note that if you used the product installer to install your product, the <EI_HOME> is located in a place specific to your OS as shown below:

    OSHome directory
    Mac OS/Library/WSO2/EnterpriseIntegrator/6.3.0
    WindowsC:\Program Files\WSO2\EnterpriseIntegrator\6.3.0\
  2. Select and download the relevant EI tooling ZIP file based on your operating system from here and then extract the ZIP file.
    The path to this folder will be referred to as <EI_TOOLING> throughout this tutorial.

  3. If you did not try the Storing and Forwarding Messages tutorial yet, open the WSO2 EI Tooling environment, click File, and then click Import. Next, select Existing WSO2 Projects into workspace under the WSO2 category, click Next and upload the pre-packaged project. This contains the configurations of the Storing and Forwarding Messages tutorial so that you do not have to repeat those steps.
  4. Download the MSF4J service from here and copy the JAR file to <EI_HOME>/wso2/msf4j/deployment/microservices folder. The back-end service is now deployed in the MSF4J profile of WSO2 EI.

Let's get started!

Setting up the message broker profile

Open the <EI_HOME>/conf/ file and add the following line after the queue.MyQueue = example.MyQueue line:


Creating the credentials for using the Gmail Connector

Creating a Client ID and Client Secret

Follow the steps below if you want to use your own email address for sending the emails.

  1. As the email sender, navigate to the URL  and log in to your google account. 
  2. If you do not already have a project, create a new project.

  3. Click Google APIs -> Credentials -> Create Credential -> OAuth client ID.

    At this point, if the consent screen name is not provided, you will be prompted to do so.

  4. Select Web Application and create a client.

  5. Provide  as the redirect URL under Authorized redirect URIs and click Create.
    The client ID and client secret will then be displayed. 

    See Gmail API documentation for details on creating the Client ID and Client Secret.

  6. Click on the Library on the side menu, and select Gmail API

  7. Click Enable.

Obtaining the Access Token and Refresh Token

Follow these steps to automatically refresh the expired token when connecting to Google API:

  1. Navigate to the URL, click at the top right corner of the screen, and select Use your own OAuth credentials
  2. Provide the client ID and client secret you previously created and click Close.
  3. Now under Step 1, select Gmail API v1 from the list of APIs, select all the scopes listed under it, and click  Authorize APIs.
  4. You will then be prompted to allow permission, click Allow.
  5. Under Step 2, click Exchange authorization code for tokens to generate an display the access token and refresh token. 

Importing the Gmail Connector into EI-Tooling

  1. Right click on Sample Services in the Project Explorer and Select Add or Remove Connector
  2. Select Add Connector and click Next.
  3. Select Connector Store location and click Connect to connect to WSO2 Connector store.
  4. Scroll down and select Gmail from the list of connectors.

  5. Click Finish
    The connector is now downloaded into your Tooling environment and the connector operations will be available in the Gmail Connector palette.

Let's use these connector operations in the configuration.

Creating the Deployable Artifacts

The connector operations are used in the PaymentRequestProcessingSequence. Select this sequence, and do the following updates:

  1. Add a Property Mediator just before the Call mediator to retrieve and store the patient's email address. 

    With the Property mediator selected, access the Property tab of the mediator and fill in the information in the following table:

    Property NameSelect New Property
    New Property Nameemail_id
    Property ActionSelect Set
    Value TypeSelect Expression
    Value Expressionjson-eval($
    DescriptionGet Email ID
  2. Add another Property mediator just after the Log mediator to retrieve and store the response sent from SettlePaymentEP. This will be used within the body of the email.

    With the Property mediator selected, access the Property tab and fill in the information in the following table:

    Property NameSelect New Property
    New Property Namepayment_response
    Property ActionSelect Set
    Value TypeSelect Expression
    Value Expressionjson-eval($.)
    DescriptionGet Payment Response
  3. Drag and drop the init method from the Gmail Connector palette adjoining the Property mediator you added in the previous step.

    With the init method selected, access the Property tab and fill in the information in the following table:

    Parameter Editor TypeSelect inline
    userIdThe sender's email address (use the email address that you used to configure the client ID and secret.)
    accessTokenThe access token you obtained.
    clientIdThe client ID you created.
    clientSecretThe client secret you created.
    refreshTokenThe refresh token you obtained.
  4. Add the sendMail method from the Gmail Connector palette and access the Property tab and fill in the information in the following table:

    Parameter Editor TypeSelect inline
    to{$ctx:email_id}Retrieves the patient email address that was stored in the relevant Property mediator.
    subjectPayment StatusThe subject line in the email that is sent out.
    messageBody{$ctx:payment_response}Retrieves the payment response that was stored in the relevant Property mediator.

    The updated PaymentRequestProcessingSequence should now look like this:

  5. Save the updated sequence configuration.
  6. Right click on SampleServicesConnectorExporter and navigate to New -> Add/Remove Connectors and select Add connector and click on Next. Select Workspace to list down the connectors that were added.

    Select the Gmail connector from the list and click OK and then Finish.

Packaging the artifacts

Since you added a connector to the Connector Exporter Project, this will need to be packaged into our existing C-App.

Package the C-App names SampleServicesCompositeApplication project with the artifacts created. 

Ensure the following artifact check boxes are selected in the Composite Application Project POM Editor.

  • SampleServices
    • HealthcareAPI
    • ClemencyEP
    • GrandOakEP
    • PineValleyEP
    • ChannelingFeeEP
    • SettlePaymentEP
  • SampleServicesRegistry
  • SampleServicesConnectorExporter

Starting the Message Broker runtime 

Start the message broker profile as follows:

Open a terminal and execute the following command:

Go to Start Menu -> Programs -> WSO2 -> Enterprise Integrator 6.3.0 Broker. This will open a terminal and start the Message Broker profile.

The message broker profile is now ready to receive messages from the ESB profile.

Starting the MSF4J profile

To be able to send requests to the back-end service (which is an MSF4J service deployed in MSF4J profile), you need to first start the MSF4J runtime:

Open a terminal and execute the following command:


Go to Start Menu -> Programs -> WSO2 -> Enterprise Integrator 6.3.0 MSF4J. This will open a terminal and start the MSF4J profile.

The Healthcare service is now active and you can start sending requests to the service.

Starting the ESB runtime and deploying the artifacts

On the Servers tab, expand the WSO2 Carbon server, right-click SampleServicesCompositeApplication, and choose Redeploy. The Console window will indicate that the CApp has been deployed successfully.

If you do not have a server added in Eclipse, refer this tutorial.

You can also deploy the artifacts to the ESB profile of WSO2 EI using a Composite Application Archive (CAR) file.

Sending requests to the ESB

  1. Create a JSON file names request.json with the following request payload. Make sure you provide a valid email address so that you can test the email being sent to the patient. 

    "name": "John Doe",
    "dob": "1940-03-19",
    "ssn": "234-23-525",
    "address": "California",
    "phone": "8770586755",
    "email": "[email protected]",
    "doctor": "thomas collins",
    "hospital": "grand oak community hospital",
    "cardNo": "7844481124110331",
    "appointment_date": "2017-04-02"
  2. Open a command line terminal and execute the following command from the location where request.json file you created is saved:

    curl -v -X POST --data @request.json http://localhost:8280/healthcare/categories/surgery/reserve --header "Content-Type:application/json"

    This is derived from the URI-Template defined when creating the API resource.


    You will see the response as follows:

    {"message":"Payment request successfully submitted. Payment confirmation will be sent via email."}

    An email will be sent to the provided patient email address with the following details:

    Subject: Payment Status
    {"appointmentNo":2,"doctorName":"thomas collins","patient":"John

You have now explored how to import the Gmail connector to the ESB profile of WSO2 EI and then use the connector operation to send emails.

  • No labels