This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.
Working with Messages in Gmail
Overview
The following operations allow you to work with messages (emails). Click an operation name to see details on how to use it.
For a sample proxy service that illustrates how to work with messages, see Sample configuration.
Operation | Description |
---|---|
Lists all messages | |
readMail | Reads a message |
sendMail | Sends a plain message |
modifyExistingMessages | Modifies an existing message |
trashMessages | Sends a message to the trash |
unTrashMessages | Removes a message from the trash |
deleteMessages | Permanently deletes a message |
sendMailWithAttachment | Sends a message with an attachment |
Operation details
This section provides further details on the operations related to messages.
Listing all messages
The listAllMails
operation lists all messages.
<gmail.listAllMails> <includeSpamTrash>{$ctx:includeSpamTrash}</includeSpamTrash> <labelIds>{$ctx:labelIds}</labelIds> <maxResults>{$ctx:maxResults}</maxResults> <pageToken>{$ctx:pageToken}</pageToken> <q>{$ctx:q}</q> </gmail.listAllMails>
Properties
includeSpamTrash
: Includes messages from SPAM and TRASH in the results. (Default: false).labelIds:
Only returns messages with labels that match all of the specified label IDs.maxResults:
Maximum number of messages to return.pageToken:
Page token to retrieve a specific page of results in the list.q:
Only returns messages matching the specified query. Supports the same query format as the Gmail search box.
Sample request
Following is a sample REST/JSON request that can be handled by the listAllMails
operation.
{ "maxResults":"10", "includeSpamTrash":"true", "pageToken":"00965906535058580458", "labelIds":"UNREAD", "q":"Jira" }
Related Gmail documentation
https://developers.google.com/gmail/api/v1/reference/users/messages/list
Reading a message
The readMail
operation retrieves a message by its ID.
<gmail.readMail> <id>{$ctx:id}</id> <format>{$ctx:format}</format> <metadataHeaders>{$ctx:metadataHeaders}</metadataHeaders> </gmail.readMail>
Properties
- id: The ID of the message to retrieve.
format
: The format to return.metadataHeaders:
When the format is METADATA, only include the headers specified in this property.
Sample request
Following is a sample REST/JSON request that can be handled by the
readMail
operation.
{ "id":"14bbb686ba287e1d", "format":"minimal" }
Related Gmail documentation
https://developers.google.com/gmail/api/v1/reference/users/messages/get
Sending a plain message
The
sendMail
operation sends a plain message.
<gmail.sendMail> <to>{$ctx:to}</to> <subject>{$ctx:subject}</subject> <from>{$ctx:from}</from> <cc>{$ctx:cc}</cc> <bcc>{$ctx:bcc}</bcc> <messageBody>{$ctx:messageBody}</messageBody> <contentType>{$ctx:contentType}</contentType> </gmail.sendMail>
Properties
to
: The email address of the recipient of the message.subject
: Subject of the message.from
: The email address of the sender of the message.cc
: The email addresses of recipients who will receive a copy of this message.bcc
: The email addresses of recipients who will privately receive a copy of this message (their email addresses will be hidden).messageBody
: Content of the message.- contentType: If the message body is in the format of html or need to send a rich text then we must give the parameter value as "text/html; charset=UTF-8" otherwise it takes the default value as text/plain
Sample request
Following is a sample REST/JSON request that can be handled by the
sendMail
operation.
{ "to":"ashalya86@gmail.com", "subject":"Hello", "cc":"vanii@gamil.com", "bcc":"elil@gmail.com", "messageBody":"Hello! Thank you for contacting us." "contentType":"text/html; charset=UTF-8" }
Related Gmail documentation
https://developers.google.com/gmail/api/v1/reference/users/messages/send
Modifying an existing message
The modifyExistingMessages
operation modifies an existing message.
<gmail.modifyExistingThreads> <id>{$ctx:id}</id> <addLabelIds>{$ctx:addLabelIds}</addLabelIds> <removeLabelIds>{$ctx:removeLabelIds}</removeLabelIds> </gmail.modifyExistingThreads>
Properties
id
: The ID of the message to modify.addLabelIds
: A list of IDs of labels to add to this message.removeLabelIds
: A list of IDs of labels to remove from this message.
Sample request
Following is a sample REST/JSON request that can be handled by the modifyExistingMessages
operation.
{ "id":"14ba5cd56fcb61ee", "addLabelIds": [ "Label_33", "Label_24" ], "removeLabelIds": [ "Label_28", "Label_31"] }
Related Gmail documentation
https://developers.google.com/gmail/api/v1/reference/users/messages/modify
Sending a message to the trash
The trashMessages
operation sends a message to the trash.
<gmail.trashMessages> <id>{$ctx:id}</id> </gmail.trashMessages>
Properties
id
: The ID of the message to trash.
Sample request
Following is a sample REST/JSON request that can be handled by the trashMessages
operation.
{ "id":"4647683792802" }
Related Gmail documentation
https://developers.google.com/gmail/api/v1/reference/users/messages/trash
Removing a message from the trash
The unTrashMessages
operation removes a message from trash.
<gmail.unTrashMessages> <id>{$ctx:id}</id> </gmail.unTrashMessages>
Properties
id
: The ID of the message to untrash
Sample request
Following is a sample REST/JSON request that can be handled by the unTrashMessages
operation.
{ "id":"4647683792802" }
Related Gmail documentation
https://developers.google.com/gmail/api/v1/reference/users/messages/untrash
Permanently deleting a message
The deleteMessages
operation permanently deletes a message. The message cannot be recovered after it is deleted. You can use trashMessages
instead if you do not want to permanently delete the message.
<gmail.deleteMessages> <id>{$ctx:id}</id> </gmail.deleteMessages>
Properties
id
: The ID of the message to delete
Sample request
Following is a sample REST/JSON request that can be handled by the deleteMessages
operation.
{ "id":"4647683792802" }
Related Gmail documentation
https://developers.google.com/gmail/api/v1/reference/users/messages/delete
Sending a message with an attachment
The sendMailWithAttachment
operation sends a message with attachments.
<gmail.sendMailWithAttachment> <subject>{$ctx:subject}</subject> <to>{$ctx:to}</to> <cc>{$ctx:cc}</cc> <bcc>{$ctx:bcc}</bcc> <messageBody>{$ctx:messageBody}</messageBody> <fileName>{$ctx:fileName}</fileName> <filePath>{$ctx:filePath}</filePath> </gmail.sendMailWithAttachment>
Properties
to
: The email addresses of the recipients of the message.subject
: Subject of the message.cc
: The email addresses of recipients who will receive a copy of this message.bcc
: The email addresses of recipients who will privately receive a copy of this message (their email addresses will be hidden).fileName: A comma-seperated list of file names of the attachments you want to include with the message.
filePath: A comma-seperated list of file paths of the attachments you want to include with the message.
messageBody: Content of the message.
Sample request
Following is a sample REST/JSON request that can be handled by the sendMailWithAttachment
operation.
{ "subject":"WSO2 Gmail Connector", "to":"hmrajas1990@gmail.com", "cc":"hmrajas1990@gmail.com", "bcc":"rajjaz@wso2.com", "messageBody":"Welcome to WSO2 ESB Gmail Connector!!!!!", "fileName":"/home/rajjaz/Documents/ESB/esb-connector-gmail/src/test/resources/artifacts/ESB/config/smile.png", "filePath":"smile.png" }
Related Gmail documentation
https://developers.google.com/gmail/api/v1/reference/users/messages/send
Sample configuration
Following is a sample proxy service that illustrates how to connect to Gmail with the init
operation and use the listAllMails
operation. The sample request for this proxy can be found in listAllMails sample request. You can use this sample as a template for using other operations in this category.
<proxy xmlns="http://ws.apache.org/ns/synapse" name="gmail_listAllMails" transports="https,http" statistics="disable" trace="disable" startOnLoad="true"> <target> <inSequence> <property name="includeSpamTrash" expression="json-eval($.includeSpamTrash)"/> <property name="labelIds" expression="json-eval($.labelIds)"/> <property name="maxResults" expression="json-eval($.maxResults)"/> <property name="pageToken" expression="json-eval($.pageToken)"/> <property name="q" expression="json-eval($.q)"/> <property name="userId" expression="json-eval($.userId)"/> <property name="refreshToken" expression="json-eval($.refreshToken)"/> <property name="clientId" expression="json-eval($.clientId)"/> <property name="clientSecret" expression="json-eval($.clientSecret)"/> <property name="accessToken" expression="json-eval($.accessToken)"/> <property name="registryPath" expression="json-eval($.registryPath)"/> <property name="apiUrl" expression="json-eval($.apiUrl)"/> <gmail.init> <userId>{$ctx:userId}</userId> <refreshToken>{$ctx:refreshToken}</refreshToken> <clientSecret>{$ctx:clientSecret}</clientSecret> <clientId>{$ctx:clientId}</clientId> <registryPath>{$ctx:registryPath}</registryPath> <accessToken>{$ctx:accessToken}</accessToken> <apiUrl>{$ctx:apiUrl}</apiUrl> </gmail.init> <gmail.listAllMails> <includeSpamTrash>{$ctx:includeSpamTrash}</includeSpamTrash> <labelIds>{$ctx:labelIds}</labelIds> <maxResults>{$ctx:maxResults}</maxResults> <pageToken>{$ctx:pageToken}</pageToken> <q>{$ctx:q}</q> </gmail.listAllMails> <respond/> </inSequence> <outSequence> <log/> <send/> </outSequence> </target> <parameter name="serviceType">proxy</parameter> <description/> </proxy>