Gmail
The Gmail connector lets you perform the read and delete operations on Gmail.
Supported versions
This connector supports Gmail REST APIs.
Before you begin
Before using the Gmail connector, do the following tasks:
- In your Google Cloud project:
- Grant the roles/connectors.admin IAM role to the user configuring the connector.
- Grant the following IAM roles to the service account that you want to use for the connector:
roles/secretmanager.viewerroles/secretmanager.secretAccessor
A service account is a special type of Google account intended to represent a non-human user that needs to authenticate and be authorized to access data in Google APIs. If you don't have a service account, you must create a service account. For more information, see Creating a service account.
- Enable the following services:
secretmanager.googleapis.com(Secret Manager API)connectors.googleapis.com(Connectors API)
To understand how to enable services, see Enabling services.
If these services or permissions have not been enabled for your project previously, you are prompted to enable them when configuring the connector.
Configure the connector
A connection is specific to a data source. It means that if you have many data sources, you must create a separate connection for each data source. To create a connection, do the following:
- In the Cloud console, go to the Integration Connectors > Connections page and then select or create a Google Cloud project.
- Click + CREATE NEW to open the Create Connection page.
- In the Location section, complete the following:
- Region: Select a location from the drop-down list.
For the list of all the supported regions, see Locations.
- Click Next.
- Region: Select a location from the drop-down list.
- In the Connection Details section, complete the following:
- Connector: Select Gmail from the list of available connectors.
- Connector version: Select the connector version from the list of available versions.
- In the Connection Name field, enter a name for the connection instance. The connection name can contain lower-case letters, numbers, or hyphens. The name must begin with a letter and end with a letter or number and the name must not exceed 49 characters.
- Description: Enter a description for the connection instance.
- Optionally, enable Cloud logging,
and then select a log level. By default, the log level is set to
Error. - Service Account: Select a service account that has the required roles.
- Optionally, configure the Connection node settings:
- Minimum number of nodes: Enter the minimum number of connection nodes.
- Maximum number of nodes: Enter the maximum number of connection nodes.
A node is a unit (or replica) of a connection that processes transactions. More nodes are required to process more transactions for a connection and conversely, fewer nodes are required to process fewer transactions. To understand how the nodes affect your connector pricing, see Pricing for connection nodes. If you don't enter any values, by default the minimum nodes are set to 2 (for better availability) and the maximum nodes are set to 50.
- + ADD LABEL: Click this to add a label to the connection in the form of a key-value pair.
- Click Next.
-
In the Authentication section, enter the authentication details.
- Select an Authentication type and enter the relevant details.
The following authentication types are supported by the Gmail connection:
- Service Account Authentication
- OAuth 2.0 - JWT Bearer
- OAuth 2.0 - Authorization code
To understand how to configure these authentication types, see Configure authentication.
- Click Next.
- Select an Authentication type and enter the relevant details.
- Review: Review your connection and authentication details.
- Click Create.
Configure authentication
Enter the details based on the authentication you want to use.
- Service Account Authentication: No additional configuration is required for this authentication type. The service account you selected in the Connection Details section will be used for authentication..
-
OAuth 2.0 - JWT Bearer
- JWT Certificate: Select the certificate to use for JWT authentication.
- Secret version: Enter the secret version of the JWT certificate.
- JWT Subject: Enter the JWT subject.
- Enable Authentication Override: Enable to override the authentication.
-
OAuth 2.0 - Authorization code
- Client ID: Enter the client ID to use for OAuth authentication.
- Scopes: Enter a list of desired scopes.
- Client Secret: The client secret to use for OAuth authentication.
- Secret version: Enter the secret version of the client secret.
- Enable Authentication Override: Enable to override the authentication.
Connection configuration samples
This section lists the sample values for the various fields that you configure when creating the connection.
OAuth 2.0 - JWT bearer connection type
| Field name | Details |
|---|---|
| Location | asia-east1 |
| Connector | Gmail |
| Connector version | 1 |
| Connection Name | gmail-jwt-conn |
| Enable Cloud Logging | true |
| Service Account | my-service-account@my-project.iam.gserviceaccount.com |
| Minimum number of nodes | 2 |
| Maximum number of nodes | 50 |
| Authentication | OAuth 2.0 - JWT Bearer |
| JWT Cert | JWT certificate |
| Secret version | 1 |
OAuth 2.0 - authorization code connection type
| Field name | Details |
|---|---|
| Location | us-central1 |
| Connector | Gmail |
| Connector version | 1 |
| Connection Name | gmail-auth-conn |
| Enable Cloud Logging | Yes |
| Service Account | my-service-account@my-project.iam.gserviceaccount.com |
| Minimum number of nodes | 2 |
| Maximum number of nodes | 50 |
| Authentication | OAuth 2.0 - Authorization code |
| Client ID | 60875425788659-mt0cm1tguyiagvst468fvaw7.apps.googleusercontent.com |
| Scopes | https://mail.google.com/ |
| Client Secret | ygdruoX-Rtyah9gzkdZc-7CB0Eng9hyaufD0VD |
| Secret version | 1 |
System limitations
The Gmail connector can process a maximum of 1 transaction per second, per node, and throttles any transactions beyond this limit. By default, Integration Connectors allocates 2 nodes (for better availability) for a connection.
For information on the limits applicable to Integration Connectors, see Limits.
Use the Gmail connection in an integration
After you create the connection, it becomes available in both Apigee Integration and Application Integration. You can use the connection in an integration through the Connectors task.
- To understand how to create and use the connectors task in Apigee Integration, see Connectors task.
- To understand how to create and use the Connectors task in Application Integration, see connectors task.
Actions
This section shows how to perform some of the actions in this connector.
SendMailMessages action
This action sends a Gmail message.
Input parameters of the SendMailMessages action
| Parameter name | Data type | Required | Description |
|---|---|---|---|
| To | String | Yes | The primary recipient's email address. For multiple recipients, use a comma-separated list. |
| AttachmentHasBytes | String | No | Set this to true if the attachment content is provided in AttachmentContentBytes (Base64-encoded), or false if the content is provided as a string in AttachmentContent. Defaults to false. |
| AttachmentFileName | String | No | The name of the file to attach. This parameter is used when AttachmentHasBytes is false or not provided. |
| Subject | String | Yes | The subject line of the email. |
| AttachmentContent | String | No | The string content of the file to attach. This parameter is used when AttachmentHasBytes is set to false or not provided. |
| BCC | String | No | The BCCed recipient's email address. For multiple recipients, use a comma-separated list. |
| AttachmentContentBytes | String | No | The Base64 encoded bytes content of the file to attach. This parameter is used when AttachmentHasBytes is set to true. |
| CC | String | No | The CCed recipient's email address. For multiple recipients, use a comma-separated list. |
| Content | String | Yes | The main content of the email message. |
| AttachmentPath | String | No | A comma-separated list of local file paths to attach to the email. |
For an example about how to configure the SendMailMessages action,
see Examples.
DownloadAttachment action
This action downloads an attachment from Gmail.
Input parameters of the DownloadAttachment action
| Parameter name | Data type | Required | Description |
|---|---|---|---|
| MessageId | String | Yes | The ID of the email. |
| DownloadLocation | String | No | The location where the attachment will be saved. |
| FileStream | String | No | An instance of an output stream where file data is written to. |
| AttachmentId | String | No | The ID of the attachment. It must be provided if the FileStream is specified. |
For an example about how to configure the DownloadAttachment action,
see Examples.
Action examples
This section shows how to perform some of the actions in this connector.
Example - Send a Gmail message
- In the
Configure connector taskdialog, clickActions. - Select the
SendMailMessagesaction, and then click Done. - In the Task Input section of the Connectors task, click
connectorInputPayloadand then enter a value similar to the following in theDefault Valuefield:{ "To": "testbristleconeemail@gmail.com", "Subject": "Data MapperCheck", "Content": "Gmail", }
If the action is successful, the
connector task's connectorOutputPayload response
parameter will have a value similar to the following:
[{
"Id": "199334f660ff462a"
}]
Example - Send a Gmail message with a JPG attachment
- In the
Configure connector taskdialog, clickActions. - Select the
SendMailMessagesaction, and then click Done. - In the Task Input section of the Connectors task, click
connectorInputPayloadand then enter a value similar to the following in theDefault Valuefield:{ "To": "testbristleconeemail@gmail.com", "Subject": "Data Mapper Email Sep10 JPG", "Content": "Gmail", "AttachmentFileName": "TestSep10.jpg", "AttachmentContentBytes": "/9j/4AAQSkZJRgABAQEBLAEsAAD/2wBDAAIBAQEBAQIBAQECAgICAgQDAgICAgUEBAMEBgUGBgYFBgYGBwkIBgcJBwYGCAsICQoKCgoKBggLDAsKDAkKCgr/2wBDAQICAgICAgUDAwUKBwYHCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgr/wAARCANUBdwDAREAAhEBAxEB/8QAHgABAAAGAwEAAAAAAAAAAAAAAAEDBAcICQIFBgr/xABsEAABAwMCBAMFBQQHAwUJACMBAgMEAAURBgcIEiExCRNBChQiUWEVIzJxgUJSkaEWFzNicrHBJEPRNFOCkqIYJTlEY4O14fDxJmRzdXZ3k7PCNTY4haOytLYZN1RVV8NIVmV0eJSWpNLT4v/EAB0BAQABBAMBAAAAAAAAAAAAAAAHAQQFBgIDCAn/xABXEQABAwURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIlESiJREoiURKIv/Z", "AttachmentHasBytes": true }
If the action is successful, the
connector task's connectorOutputPayload response
parameter will have a value similar to the following:
[{
"Id": "199334f660ff462a"
}]
Example - Send a Gmail message with a PDF attachment
- In the
Configure connector taskdialog, clickActions. - Select the
SendMailMessagesaction, and then click Done. - In the Task Input section of the Connectors task, click
connectorInputPayloadand then enter a value similar to the following in theDefault Valuefield:{ "To": "testbristleconeemail@gmail.com", "Subject": "Data Mapper Email Sep10", "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asirp0ZqjD4b/YDK6Gb1sOGVuCfoNjrBjFF31EuLaQmNckf0J9HXqIi66Wv0DdjkYFPqBiqgy+k6+jLLVv4B0J30dZpmCXy", "AttachmentHasBytes": true }
If the action is successful, the
connector task's connectorOutputPayload response
parameter will have a value similar to the following:
[{
"Id": "1993341d558d7b07"
}]
Example - Send a Gmail message with a TXT attachment
- In the
Configure connector taskdialog, clickActions. - Select the
SendMailMessagesaction, and then click Done. - In the Task Input section of the Connectors task, click
connectorInputPayloadand then enter a value similar to the following in theDefault Valuefield:{ "To": "testbristleconeemail@gmail.com", "Subject": "Data Mapper Email Sep10", "Content": "Gmail", "AttachmentFileName": "TestSep10.txt", "AttachmentContent": "TestingwithAttachment", "AttachmentHasBytes": true }
If the action is successful, the
connector task's connectorOutputPayload response
parameter will have a value similar to the following:
[{
"Id": "1993341d558d7b07"
}]
Example - Download an attachment from Gmail
- In the
Configure connector taskdialog, clickActions. - Select the
DownloadAttachmentaction, and then click Done. - In the Task Input section of the Connectors task, click
connectorInputPayloadand then enter a value similar to the following in theDefault Valuefield:{ "MessageId": "198acdcde5c09ce5" }
If the action is successful, the
connector task's connectorOutputPayload response
parameter will have a value similar to the following:
[{
"Success": "true",
"MessageId": "198acdcde5c09ce5",
"AttachmentId": "1",
"Size": "58005",
"Data": "JVBERi0xLjQKJdPr6eEKMSAwIG9iago8PC9UaXRsZSAoYWJvdXQ6YmxhbmspCi9DcmVhdG9yIChNb3ppbGxhLzUuMCBcKFgxMTsgTGludXggeDg2XzY0XCkgQXBwbGVXZWJLaXQvNTM3LjM2IFwoS0hUTUwsIGxpa2UgR2Vja29cKSBIZWFkbGVzc0Nocm9tZS8xMzguMC4wLjAgU2FmYXJpLzUzNy4zNikKL1Byb2R1Y2VyIChTa2lhL1BERiBtMTM4KQovQ3JlYXRpb25EYXRlIChEOjIwMjUwODE1MDgwMDE2KzAwJzAwJykKL01vZERhdGUgKEQ6MjAyNTA4MTUwODAwMTYrMDAnMDAnKT4-CmVuZG9iagozIDAgb2JqCjw8L2NhIDEKL0JNIC9Ob3JtYWw-PgplbmRvYmo",
"Filename": "My_Store_404672162.pdf",
"@isoutervalue": null
}]
Entity operation examples
This section shows how to perform some of the entity operations in this connector.
Example - List all the Gmail messages
- In the
Configure connector taskdialog, clickEntities. - Select
Messagesfrom theEntitylist. - Select the
Listoperation, and then click Done. - In the Task Input section of the Connectors task, you can set the filterClause as per the customer requirement.
You must use single quotes (') to enclose the value for a filterClause. You can use the filterClause to filter records based on the columns.
Example - Get a Gmail message details from inbox
- In the
Configure connector taskdialog, clickEntities. - Select
Inboxfrom theEntitylist. - Select the
Getoperation, and then click Done. - Set the entityId to
1which is the key to be passed. To set the entityId, in the Data Mapper section of the Data Mapping, click Open Data Mapping Editor and then enter1in the Input Value field and choose the entityId as local variable.
The value for entityId must be passed directly, such as "1". Here, "1" is the unique primary key value, which is passed.
In some cases, passing a single entityId may cause an error because the entity has two composite keys. In such cases, you can use the filterClause and pass the value, such as id='1'.
Example - Delete a Gmail message
- In the
Configure connector taskdialog, clickEntities. - Select
Messagesfrom theEntitylist. - Select the
Deleteoperation, and then click Done. - Set the entityId to
1which is the key to be passed. - To set the entityId, in the Data Mapper section of the Data Mapping, click Open Data Mapping Editor and then enter
1in the Input Value field and choose the entityId as local variable.If entity has two composite business or primary keys instead of specifying the entityId, you can also set the filterClause to
id='1'.
Get help from the Google Cloud community
You can post your questions and discuss this connector in the Google Cloud community at Cloud Forums.What's next
- Understand how to suspend and resume a connection.
- Understand how to monitor connector usage.
- Understand how to view connector logs.