Logo
Home
Resources

Product

Custom Workflow

Resources

Blog
Youtube
Template
Home
>
Product
>
Template Top
>
detail

[GAS Library] Gmail to Slack Forwarder Library

A Google Apps Script library that automatically forwards Gmail messages to Slack channels based on specified labels and conditions.

‍

Demo Video

Over view
Code

Detail

📋 Description

This library provides a simple and powerful way to monitor specific Gmail labels and automatically forward new emails to Slack channels. Perfect for teams that need instant notifications for customer inquiries, sales leads, or other important emails.

Key Features

  • ✅ Multi-language support (English/Japanese)
  • ✅ Customizable message formatting
  • ✅ Timezone support
  • ✅ Duplicate prevention
  • ✅ Error handling and logging
  • ✅ Easy configuration management

🚀 Quick Setup

Step 1: Get Slack Webhook URL

Create a Slack webhook URL by following this guide: How to Get Slack Webhook URL

Step 2: Add Library to Your Project

  1. Create a new Google Apps Script project
  2. Go to "Libraries" → "Add a library"
  3. Enter Library ID: [ 1kldK2eftHl5t8xngwYApWNWkX079ZlwFiMO0zJBhU47dCrj3YlVfXFOf ]
  1. Set identifier: GmailSlackLib
  2. Save

Step 3: Create Your Script

function advancedEmailForwarder() {
  const config = {
    slack: {
      webhookUrl: "https://hooks.slack.com/services/YOUR/WEBHOOK/URL",
      channelId: "#alerts",
      botName: "Company Bot",
      botIcon: ":envelope:",
    },
    gmail: {
      targetLabels: ["Customer-Inquiry", "Sales-Lead"],
      processedLabelName: "Slack-Sent",
      timeWindowMinutes: 10,
      searchLimit: 100,
    },
    language: "ja", // 日本語
    timezone: "Asia/Tokyo"
  };
  
  const forwarder = GmailSlackLib.createForwarder(config);
  const result = forwarder.forwardEmails();
  console.log(result);
}

‍

⚙️ Configuration Options

Slack Configuration

  • webhookUrl: Your Slack webhook URL (required)
  • channelId: Target Slack channel (e.g., "#alerts", "#general")
  • botName: Display name for the bot in Slack
  • botIcon: Emoji icon for the bot (see options below)

Gmail Configuration

  • targetLabels: Array of Gmail labels to monitor
  • processedLabelName: Label added to processed emails
  • timeWindowMinutes: Time window to check for new emails (in minutes)
  • searchLimit: Maximum number of threads to process per run

General Configuration

  • language: Interface language ("en" or "ja")
  • timezone: Timezone for date formatting (see country codes below)

🎨 Bot Icon Options

Choose from these emoji options for your Slack bot:

botIcon: ":envelope:",        // 📧 
botIcon: ":email:",          // 📧 
botIcon: ":incoming_envelope:", // 📨 
botIcon: ":postbox:",        // 📮 
botIcon: ":mailbox:",        // 📫 
botIcon: ":robot_face:",     // 🤖 
botIcon: ":computer:",       // 💻 
botIcon: ":bell:",           // 🔔 
botIcon: ":loudspeaker:",    // 📢
botIcon: ":mega:",           // 📣 
botIcon: ":warning:",        // ⚠️ 
botIcon: ":information_source:", // ℹ️
botIcon: ":white_check_mark:", // ✅ 
botIcon: ":smiley:",         // 😄 
botIcon: ":smile:",          // 😄 
botIcon: ":sunglasses:",     // 😎 
botIcon: ":nerd_face:",      // 🤓 
botIcon: ":ghost:",          // 👻 
botIcon: ":alien:",          // 👽 

‍

🌍 Timezone Examples

Set timezone using standard timezone identifiers. For country-specific codes, refer to: ISO 3166-1 Country Codes

Common timezone examples:

  • "Asia/Tokyo" - Japan
  • "America/New_York" - Eastern US
  • "America/Los_Angeles" - Pacific US
  • "Europe/London" - UK
  • "Europe/Berlin" - Germany
  • "Asia/Shanghai" - China
  • "Asia/Seoul" - South Korea
  • "Australia/Sydney" - Australia

‍

‍

Source Code

HTML
CSS
Javascript

FAQ

Is this an official, standard feature built into Google or Slack?

No, it is not. This is a custom function that uses a third-party Google Apps Script (GAS) library (GmailSlackLib). To use it, you must add the specified library ID to your GAS project and create/configure the setup script (advancedEmailForwarder function) yourself, as shown in Step 3.

Will the same email be forwarded to Slack multiple times, creating duplicates?

No, duplicate sending is prevented. The setting gmail.processedLabelName (e.g., "Slack-Sent") handles this. The library automatically applies this specified label to any email it forwards to Slack. The next time it searches, it only looks for emails without this label, which prevents them from being sent again.

Can I monitor multiple Gmail labels at the same time, such as "Customer-Inquiry" and "Sales-Lead"?

Yes, you can. The gmail.targetLabels setting is an array (a list). As shown in the Step 3 example, you can write ["Customer-Inquiry", "Sales-Lead"] to specify multiple labels. Any new email that has either of those labels will be forwarded to Slack.

Search

Search more

Related Template

Need Customization?

We can customize this sample to match your specific business requirements.

Book Free Consultation

Got a quick dev request?

Put it on Trello!Need a fix for HubSpot, CMS, or GAS? Post it on Trello.

Development Requests Here

GAS Library: Automated Blog Post NG Word Checking with AI (Gemini/OpenAI)

HubSpot Custom Workflow Guide: How to Find a Contact's "Most Recent Campaign"

HubSpot Custom Workflow Guide: How to "Search" for Products and Get Price/SKU Data

GAS Library Guide: How to Automatically Check for Broken Links in Google Sheets

HubSpot Custom Workflow Guide: How to Auto-Search and Recommend Marketing Events

Company Info
Name : SweetsVillage .Inc
CEO :
‍
Tomoo Motoyama

HomeTemplateCustomWorkflow
Terms & ConditionsPrivacy PolicyContact us

Copyright ©SweetsVillage .Inc

Back To Top Image