ByteChef LogoByteChef

Gmail

Gmail is a widely used email service by Google, offering free and feature-rich communication, organization, and storage capabilities accessible through web browsers and mobile apps.

Categories: Communication

Type: googleMail/v1


Connections

Version: 1

OAuth2 Authorization Code

Properties

NameLabelTypeDescriptionRequired
clientIdClient IdSTRINGtrue
clientSecretClient SecretSTRINGtrue

Connection Setup

Create OAuth 2.0 Application

Creation of OAuth 2.0 application is documented here.

Enable Gmail API

  1. In the Google Cloud Console, select your project.
  2. Go to the APIs & Services.
  3. Click on ENABLE APIS AND SERVICES.
  4. Search for "gmail api" in the search bar.
  5. Click on Gmail API.
  6. Click Enable.

Actions

Add Labels

Name: addLabels

Add labels to an email in your Gmail account.

Properties

NameLabelTypeDescriptionRequired
idMessage IDSTRINGID of the message to add labels.true
labelIdsLabels IDsARRAY
Items [STRING]
ID of the labels to add to message. You can add up to 100 labels with each update.true

Example JSON Structure

{
  "label" : "Add Labels",
  "name" : "addLabels",
  "parameters" : {
    "id" : "",
    "labelIds" : [ "" ]
  },
  "type" : "googleMail/v1/addLabels"
}

Output

Type: OBJECT

Properties

NameTypeDescription
idSTRINGThe ID of the message.
threadIdSTRINGThe ID of the thread the message belongs to.
labelIdsARRAY
Items [STRING]
List of IDs of labels applied to this message.

Output Example

{
  "id" : "",
  "threadId" : "",
  "labelIds" : [ "" ]
}

Find Message ID

To find the Message ID, click here.

Find Label ID

To find the Label ID, click here.

Archive Email

Name: archiveEmail

Archive an email message.

Properties

NameLabelTypeDescriptionRequired
idMessage IDSTRINGID of the message to be archived.true

Example JSON Structure

{
  "label" : "Archive Email",
  "name" : "archiveEmail",
  "parameters" : {
    "id" : ""
  },
  "type" : "googleMail/v1/archiveEmail"
}

Output

Type: OBJECT

Properties

NameTypeDescription
idSTRINGThe ID of the message.
threadIdSTRINGThe ID of the thread the message belongs to.
labelIdsARRAY
Items [STRING]
List of IDs of labels applied to this message.

Output Example

{
  "id" : "",
  "threadId" : "",
  "labelIds" : [ "" ]
}

Find Message ID

To find the Message ID, click here.

Create Label

Name: createLabel

Creates a new label.

Properties

NameLabelTypeDescriptionRequired
nameNameSTRINGThe display name of the newly created label.true

Example JSON Structure

{
  "label" : "Create Label",
  "name" : "createLabel",
  "parameters" : {
    "name" : ""
  },
  "type" : "googleMail/v1/createLabel"
}

Output

Type: OBJECT

Properties

NameTypeDescription
idSTRINGID of the newly created label.
labelListVisibilitySTRINGThe visibility of the label in the label list in the Gmail web interface.
messageListVisibilitySTRINGThe visibility of messages with this label in the message list in the Gmail web interface.
nameSTRINGThe display name of the label.

Output Example

{
  "id" : "",
  "labelListVisibility" : "",
  "messageListVisibility" : "",
  "name" : ""
}

Delete Email

Name: deleteEmail

Deletes an email from your Gmail account immediately and permanently.

Properties

NameLabelTypeDescriptionRequired
idMessage IDSTRINGThe ID of the message to delete.true

Example JSON Structure

{
  "label" : "Delete Email",
  "name" : "deleteEmail",
  "parameters" : {
    "id" : ""
  },
  "type" : "googleMail/v1/deleteEmail"
}

Output

This action does not produce any output.

Get Email

Name: getEmail

Gets the specified email message.

Properties

NameLabelTypeDescriptionRequired
idMessage IDSTRINGThe ID of the message to retrieve.true
formatFormatSTRING
Options SIMPLE, MINIMAL, FULL, RAW, metadata
The format to return the message in.false
metadataHeadersMetadata headersARRAY
Items [STRING]
When given and format is METADATA, only include headers specified.false

Example JSON Structure

{
  "label" : "Get Email",
  "name" : "getEmail",
  "parameters" : {
    "id" : "",
    "format" : "",
    "metadataHeaders" : [ "" ]
  },
  "type" : "googleMail/v1/getEmail"
}

Output

The output for this action is dynamic and may vary depending on the input parameters. To determine the exact structure of the output, you need to execute the action.

Get Thread

Name: getThread

Gets the specified thread.

Properties

NameLabelTypeDescriptionRequired
idThread IDSTRINGThe ID of the thread to retrieve.true
formatFormatSTRING
Options SIMPLE, MINIMAL, FULL, RAW, metadata
The format to return the message in.false
metadataHeadersMetadata headersARRAY
Items [STRING]
When given and format is METADATA, only include headers specified.false

Example JSON Structure

{
  "label" : "Get Thread",
  "name" : "getThread",
  "parameters" : {
    "id" : "",
    "format" : "",
    "metadataHeaders" : [ "" ]
  },
  "type" : "googleMail/v1/getThread"
}

Output

The output for this action is dynamic and may vary depending on the input parameters. To determine the exact structure of the output, you need to execute the action.

Find Message ID

To find the Thread ID, click here.

List Labels

Name: listLabels

Lists all labels in your mailbox.

Example JSON Structure

{
  "label" : "List Labels",
  "name" : "listLabels",
  "type" : "googleMail/v1/listLabels"
}

Output

Type: ARRAY

Items Type: OBJECT

Properties

NameTypeDescription
nameSTRINGThe display name of the label.
idSTRINGID of the label.
messageListVisibilitySTRINGThe visibility of messages with this label in the message list in the Gmail web interface.
labelListVisibilitySTRINGThe visibility of the label in the label list in the Gmail web interface.
typeSTRINGThe owner type for the label.

Output Example

[ {
  "name" : "",
  "id" : "",
  "messageListVisibility" : "",
  "labelListVisibility" : "",
  "type" : ""
} ]

Remove Labels

Name: removeLabels

Removes labels on the specified message.

Properties

NameLabelTypeDescriptionRequired
idMessage IDSTRINGID of the message to remove labels.true
labelIdsLabels IDsARRAY
Items [STRING]
ID of the labels to remove from message.true

Example JSON Structure

{
  "label" : "Remove Labels",
  "name" : "removeLabels",
  "parameters" : {
    "id" : "",
    "labelIds" : [ "" ]
  },
  "type" : "googleMail/v1/removeLabels"
}

Output

Type: OBJECT

Properties

NameTypeDescription
idSTRINGThe ID of the message.
threadIdSTRINGThe ID of the thread the message belongs to.
labelIdsARRAY
Items [STRING]
List of IDs of labels applied to this message.

Output Example

{
  "id" : "",
  "threadId" : "",
  "labelIds" : [ "" ]
}

Find Message ID

To find the Message ID, click here.

Find Label ID

To find the Label ID, click here.

Reply to Email

Name: replyToEmail

Send a reply to an email message.

Properties

NameLabelTypeDescriptionRequired
idMessage IDSTRINGThe ID of the message to reply to.true
toToARRAY
Items [STRING]
Recipients email addresses.true
bccBccARRAY
Items [STRING]
Bcc recipients email addresses.false
ccCcARRAY
Items [STRING]
Cc recipients email addresses.false
bodyTypeBody TypeSTRING
Options plain, html
true
bodyBody - TextSTRINGThe body of the message in text format.true
bodyBody - HTMLSTRINGThe body of the message in HTML format.true
attachmentsAttachmentsARRAY
Items [FILE_ENTRY]
A list of attachments to send with the email.false

Example JSON Structure

{
  "label" : "Reply to Email",
  "name" : "replyToEmail",
  "parameters" : {
    "id" : "",
    "to" : [ "" ],
    "bcc" : [ "" ],
    "cc" : [ "" ],
    "bodyType" : "",
    "body" : "",
    "attachments" : [ {
      "extension" : "",
      "mimeType" : "",
      "name" : "",
      "url" : ""
    } ]
  },
  "type" : "googleMail/v1/replyToEmail"
}

Output

Type: OBJECT

Properties

NameTypeDescription
idSTRINGThe ID of the message.
threadIdSTRINGThe ID of the thread the message belongs to.
labelIdsARRAY
Items [STRING]
List of IDs of labels applied to this message.

Output Example

{
  "id" : "",
  "threadId" : "",
  "labelIds" : [ "" ]
}

Find Message ID

To find the Message ID, click here.

Search Email

Name: searchEmail

Lists the email messages in the user's mailbox.

Properties

NameLabelTypeDescriptionRequired
maxResultsMax ResultsNUMBERMaximum number of messages to return.false
pageTokenPage TokenSTRINGPage token to retrieve a specific page of results in the list.false
fromFromSTRINGThe address sending the mailfalse
toToSTRINGThe address receiving the new mailfalse
subjectSubjectSTRINGWords in the subject linefalse
categoryCategorySTRING
Options primary, social, promotions, updates, forums, reservations, purchases
Messages in a certain categoryfalse
labelIdsLabelsARRAY
Items [STRING]
Only return messages with labels that match all of the specified label IDs. Messages in a thread might have labels that other messages in the same thread don't have.false
includeSpamTrashInclude Spam TrashBOOLEAN
Options true, false
Include messages from SPAM and TRASH in the results.false

Example JSON Structure

{
  "label" : "Search Email",
  "name" : "searchEmail",
  "parameters" : {
    "maxResults" : 0.0,
    "pageToken" : "",
    "from" : "",
    "to" : "",
    "subject" : "",
    "category" : "",
    "labelIds" : [ "" ],
    "includeSpamTrash" : false
  },
  "type" : "googleMail/v1/searchEmail"
}

Output

Type: OBJECT

Properties

NameTypeDescription
messagesARRAY
Items [{STRING(id), STRING(threadId)}]
nextPageTokenSTRING
resultSizeEstimateNUMBEREstimated number of messages.

Output Example

{
  "messages" : [ {
    "id" : "",
    "threadId" : ""
  } ],
  "nextPageToken" : "",
  "resultSizeEstimate" : 0.0
}

Send Email

Name: sendEmail

Creates and sends a new email message from your Gmail account.

Properties

NameLabelTypeDescriptionRequired
toToARRAY
Items [STRING]
Recipients email addresses.true
subjectSubjectSTRINGSubject of the email.true
bccBccARRAY
Items [STRING]
Bcc recipients email addresses.false
ccCcARRAY
Items [STRING]
Cc recipients email addresses.false
replyToReply ToARRAY
Items [STRING]
Reply-to email addresses.false
bodyTypeBody TypeSTRING
Options plain, html
true
bodyBody - TextSTRINGThe body of the message in text format.true
bodyBody - HTMLSTRINGThe body of the message in HTML format.true
attachmentsAttachmentsARRAY
Items [FILE_ENTRY]
A list of attachments to send with the email.false

Example JSON Structure

{
  "label" : "Send Email",
  "name" : "sendEmail",
  "parameters" : {
    "to" : [ "" ],
    "subject" : "",
    "bcc" : [ "" ],
    "cc" : [ "" ],
    "replyTo" : [ "" ],
    "bodyType" : "",
    "body" : "",
    "attachments" : [ {
      "extension" : "",
      "mimeType" : "",
      "name" : "",
      "url" : ""
    } ]
  },
  "type" : "googleMail/v1/sendEmail"
}

Output

Type: OBJECT

Properties

NameTypeDescription
idSTRINGThe ID of the message.
threadIdSTRINGThe ID of the thread the message belongs to.
labelIdsARRAY
Items [STRING]
List of IDs of labels applied to this message.

Output Example

{
  "id" : "",
  "threadId" : "",
  "labelIds" : [ "" ]
}

Triggers

New Email

Name: newEmail

Triggers when new mail is found in your Gmail inbox.

Type: STATIC_WEBHOOK

Properties

NameLabelTypeDescriptionRequired
topicNameTopic NameSTRINGName of your PubSub topic you want to subscribe to.true
formatFormatSTRING
Options SIMPLE, MINIMAL, FULL, RAW, metadata
The format to return the message in.false

Output

The output for this action is dynamic and may vary depending on the input parameters. To determine the exact structure of the output, you need to execute the action.

JSON Example

{
  "label" : "New Email",
  "name" : "newEmail",
  "parameters" : {
    "topicName" : "",
    "format" : ""
  },
  "type" : "googleMail/v1/newEmail"
}

New Email Trigger Setup

Setting up Pub/Sub service

  1. Deploy a project that has New Mail Trigger.
  2. Click this icon to copy the static webhook URL.
  3. In the search bar enter pub/sub.
  4. Click on Pub/Sub.
  5. Click on Create topic.
  6. Enter your topic name.
  7. Click on Create.
  8. Click on Subscriptions.
  9. Click on your automatically created subscription.
  10. Click on Edit.
  11. Select Push.
  12. Click on Endpoint URL and paste the previously copied URL.
  13. Select Never expire.
  14. Click on Update.
  15. Click on Topics.
  16. Click here.
  17. Click on Add principal.
  18. Add gmail-api-push@system.gserviceaccount.com as the new principal.
  19. Click here.
  20. Click on Pub/Sub Publisher.
  21. Click on Save.
  22. Click on MyTopic.
  23. This is your topic name.

New Email Polling

Name: newEmailPolling

Periodically checks your Gmail inbox for any new incoming emails.

Type: POLLING

Properties

NameLabelTypeDescriptionRequired
formatFormatSTRING
Options SIMPLE, MINIMAL, FULL, RAW, metadata
The format to return the message in.false

Output

The output for this action is dynamic and may vary depending on the input parameters. To determine the exact structure of the output, you need to execute the action.

JSON Example

{
  "label" : "New Email Polling",
  "name" : "newEmailPolling",
  "parameters" : {
    "format" : ""
  },
  "type" : "googleMail/v1/newEmailPolling"
}

New Email Pooling Trigger Setup

Turning on Google Calendar API

Gmail doesn’t manage its own time zone; it inherits the time zone from your Google Calendar settings, so we rely on the Calendar API to resolve times correctly.

  1. Go to the Google Cloud Console.
  2. Click on APIs & Services.
  3. In search bar enter "Google Calendar API".
  4. Click on Google Calendar API.
  5. Click on Enable.
  6. Done 🚀

What to do if your action is not listed here?

If this component doesn't have the action you need, you can use Custom Action to create your own. Custom Actions empower you to define HTTP requests tailored to your specific requirements, allowing for greater flexibility in integrating with external services or APIs.

To create a Custom Action, simply specify the desired HTTP method, path, and any necessary parameters. This way, you can extend the functionality of your component beyond the predefined actions, ensuring that you can meet all your integration needs effectively.


Additional Instructions

How to find Message ID

The best way to find a message ID is to use the output of one of the Gmail actions or triggers. In the output, you will find an id property, which represents the message ID.

Some actions and triggers that return a message ID:

  • Search Email
  • Get Mail
  • Send Email
  • New Email trigger

Via API

  • Use the GET https://gmail.googleapis.com/gmail/v1/users/{userId}/messages endpoint.
  • Lists the messages in the user's mailbox.

How to find Label ID

The best way to find a label ID is to use the List Labels action. It returns a list of labels, each containing a name and an id.

Via API

  • Use the GET https://gmail.googleapis.com/gmail/v1/users/{userId}/labels endpoint.
  • Lists all labels in the user's mailbox.

How to find Thread ID

The best way to find a thread ID is to use the output of Gmail actions such as Get Thread, Get Mail, or Search Email. In the output, you will find a threadId property.

Via API

  • Use the GET https://gmail.googleapis.com/gmail/v1/users/{userId}/threads endpoint.
  • Lists the threads in the user's mailbox.

Troubleshooting

Access Blocked: Verification Process Not Completed

Documentation for how to add a test user can be found here

anl-c-google-mail-md

How is this guide?

Last updated on

On this page