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


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.
Create a Slack webhook URL by following this guide: How to Get Slack Webhook URL
[ 1kldK2eftHl5t8xngwYApWNWkX079ZlwFiMO0zJBhU47dCrj3YlVfXFOf ]GmailSlackLibfunction 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);
}
webhookUrl: Your Slack webhook URL (required)channelId: Target Slack channel (e.g., "#alerts", "#general")botName: Display name for the bot in SlackbotIcon: Emoji icon for the bot (see options below)targetLabels: Array of Gmail labels to monitorprocessedLabelName: Label added to processed emailstimeWindowMinutes: Time window to check for new emails (in minutes)searchLimit: Maximum number of threads to process per runlanguage: Interface language ("en" or "ja")timezone: Timezone for date formatting (see country codes below)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:", // 👽
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
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.
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.
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.
We can customize this sample to match your specific business requirements.
Book Free ConsultationPut it on Trello!Need a fix for HubSpot, CMS, or GAS? Post it on Trello.
Development Requests Here