The Gmail connector allows you to access the Gmail REST API through WSO2 ESB and send an Email. Gmail is a free, Web-based e-mail service provided by Google.
First download the Gmail Connector from WSO2 store. And Start the WSO2 ESB server using below steps.
- download the ESB runtime ZIP file, and then extract the ZIP file.
The path to this folder will be referred to as<ESB_HOME>
throughout the post. - Navigate to the
<PRODUCT_HOME>/bin/
directory using the Command Prompt. - To start the server in a typical environment:
- On Windows:
wso2server.bat --run
- On Linux/Mac OS:
sh wso2server.sh
- On Windows:
- To start the server in the background mode of Linux:
sh wso2server.sh start
To stop the server running in this mode, you will enter:sh wso2server.sh stop
now go to https://localhost:9443/carbon and log into the management console
using username admin and password admin
Step 1 :
Now go to Home -> Manage -> Connectors -> Add.
Upload the downloaded Gmail Connector zip file. Then change the status as enabled.
Step 2 :
Then create a custom proxy service with the name as Send_email_proxy and go to the source view.
copy and paste below source code to your source
<?xml version="1.0" encoding="UTF-8"?> <proxy xmlns="http://ws.apache.org/ns/synapse" name="Send_email_proxy" transports="http,https" statistics="disable" trace="disable" startOnLoad="true"> <target> <inSequence> <property name="userId" expression="json-eval($.userId)"/> <property name="accessToken" expression="json-eval($.accessToken)"/> <property name="apiUrl" expression="json-eval($.apiUrl)"/> <property name="to" expression="json-eval($.to)"/> <property name="subject" expression="json-eval($.subject)"/> <property name="from" expression="json-eval($.from)"/> <property name="messageBody" expression="json-eval($.messageBody)"/> <gmail.init> <userId>{$ctx:userId}</userId> <accessToken>{$ctx:accessToken}</accessToken> <apiUrl>{$ctx:apiUrl}</apiUrl> </gmail.init> <gmail.sendMail> <to>{$ctx:to}</to> <subject>{$ctx:subject}</subject> <from>{$ctx:from}</from> <messageBody>{$ctx:messageBody}</messageBody> </gmail.sendMail> <respond/> </inSequence> </target> <description/> </proxy>
Step 3:
Step 4:
Now you need to create an app to connect to Gmail API.The Gmail API uses OAuth2 authentication with acessToken. Go to OAuth 2.0 Playground and select the needed API s and authorize them using your gmail account. Click on Exchange authorization code for tokens in the next window and copy the access_token code from the JSON response.
Step 4:
Now we are ready to test our proxy service. We can test our proxy using Postman by sending a JSON request as follows.
I got a new email with "wso2 gmail connector" as the subject.
Reference :
Comments
Post a Comment