Skip to main content

Sending an email using WSO2 Gmail Connector


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
  • 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:

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

Popular posts from this blog

Understanding C1 and C2 Compilers in Java

Understanding C1 and C2 Compilers in Java Understanding C1 and C2 Compilers in Java In Java, the Just-In-Time (JIT) compiler is a part of the Java Virtual Machine (JVM) that improves the performance of Java applications by compiling bytecode into native machine code at runtime. The JIT compiler includes two different compilers, known as the C1 and C2 compilers, each with distinct optimization strategies and purposes. C1 Compiler (Client Compiler) The C1 compiler, also known as the client compiler, is designed for fast startup times and lower memory consumption. It performs lighter and quicker optimizations, which makes it suitable for applications that require quick startup and responsiveness. Key characteristics of the C1 compiler include: Quick Compilation: Prioritizes fast compilation times over deep optimizations. Low Overhead: Consumes less memory and resources during compilation. Profile-Guided Optimization: Ca...

Understanding -XX:+PrintCompilation Output in Java

Understanding -XX:+PrintCompilation Output in Java Understanding -XX:+PrintCompilation Output in Java The -XX:+PrintCompilation flag in the Java Virtual Machine (JVM) prints information about the methods being compiled by the Just-In-Time (JIT) compiler. When you enable this flag, the JVM will output a log of compilation events to the standard output. Each line of the output provides information about a specific method being compiled. Here, I'll explain the meaning of the different columns and markers, specifically focusing on the n , s , and % markers as seen in your example. Explanation of Output Columns and Markers Here's a breakdown of what each column and marker means: Timestamp : The time (in milliseconds) since the JVM started when the compilation event occurred. Compilation ID : A unique identifier for each compilation task within the JVM's lifecycle. Optimization Level : The lev...

What is L1, L2 and L3 Support Engineering

In this blog article, I'm going to explain about the Software support engineering role with my experience. I was a Level 2 and 3 support Engineer during my career. L1 - Level 1 L2 - Level 2 L3 - Level 3 Ticket - Incident L1 support includes interacting with customers, understand their issue and create tickets against it. The ticket then routed to the relevant L2 support ( Integration support, Server & Storage support, etc ...). L1 support Engineers have basic knowledge of product/service and skill to troubleshoot a very basic issue like password reset, software installation/uninstallation/reinstallation. L2 support manages the tickets which routed to them by L1( L2 support also can create tickets against any issue notice by them). They have more knowledge, more experience in solving related complex issues and can guide/help L1 support folks job in troubleshooting. If the solution not provided at this level then escalate to the L3. L3 is ...