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 ]GmailSlackLib
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);
}
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
We can customize this sample to match your specific business requirements.
Book Free Consultation