Hello, this is Kim Jaewook from ClassMethod. This time, we’ve summarized how to send unconfirmed email notifications to Slack using Google Apps Script.
Please refer to the blog below for information on how to send a message to a Slack channel using Google Apps Script.
advance preparation
Prerequisites include the Slack webhook URL, the Slack channel’s email address, and the Slack channel’s name.
To find the email address of a Slack channel, click on the relevant Slack channel. [통합] → [이 채널에 이메일 보내기]You can check it here.
Please refer to the following for information introduced in Slack’s official documentation.
Write code
function send_notification_to_slack_when_mail_arrived() {
const slack_webhook_url=”SlackのWebhook URL”;
const hours = 24;
const fromMail = [‘Jaewook Kim’]
const transferAddr=”Slack channel email address” const slackCh=”Slack channel name” let date = new Date(); let unixtime = Math.floor(date.getTime() / 1000); unixtime = unixtime – (hours * 3600); // is:read checks read emails, is:unread checks unread emails const query = ‘after:’ + unixtime + ‘ ‘ + ‘from:’ + fromMail.join(‘ OR ‘) + ‘ is :read’; const threads = GmailApp.search(query); if (threads.length == 0) { return; } let result = []; for (let i = 0; i ‘ + ‘n’ + ‘There is an unconfirmed email.’ + ‘n’ + ‘Please check the unconfirmed email!!!’ + ‘n’ + ‘ }; const payload = JSON.stringify(json); const options = { ‘method’: ‘post’, ‘contentType’: ‘application/json’, ‘payload’: payload }; UrlFetchApp.fetch(slack_webhook_url, options);
The code refers to the blog below.
Enter the Slack Webhook URL prepared in advance, the Slack channel email address, and the Slack channel name.
Also, const fromMail = [‘Jaewook Kim’]This determines which person you want to identify emails sent from. For example, if you want to be notified of emails sent by Jaewook Kim, enter Jaewook Kim.
Check results
When you check the results, you will receive a message in your Slack channel asking you to check for unconfirmed emails.
For testing purposes, set is:read to check emails read within 24 hours, and if a matching email is found, an alarm will be sent to Slack.
If you have any questions after reading this blog post, please send them to [email protected].
**Considering the increasing use of AI in email management, how might the integration of AI capabilities, such as sentiment analysis or email summarization, enhance this existing automation solution?**
## Interview: Automating Unread Email Notifications with Google Apps Script
**Introduction:**
Welcome to World Today News. Today, we are joined by two experts, [Guest 1 Name] and [Guest 2 Name], to discuss an innovative method for streamlining email management using Google Apps Script. This method, detailed in a recent blog post by Kim Jaewook from ClassMethod, allows users to automatically receive Slack notifications about unread emails.
**Section 1: Setting the Stage**
* **Interviewer:** Kim Jaewook’s method leverages the power of Google Apps Script and Slack. For our audience who may be unfamiliar with these tools, can you explain briefly what they are and how they can be beneficial for professionals?
* **Guest 1:** [Answer focusing on Google Apps Script, its functionality, and benefits]
* **Guest 2:** [Answer focusing on Slack, highlighting its role in team communication and collaboration]
**Section 2: The Power of Automation**
* **Interviewer:** The article details the process of setting up automated email notifications via Slack. Can you walk us through the key steps involved? What are the pre-requisites for this setup?
* **Guest 1:** [Explaining the main steps outlined in the article, focusing on the technical aspects like Slack webhook URL, channel email address, and Google Apps Script code.]
* **Guest 2:** [Adding practical insights and highlighting potential challenges a user might encounter during setup]
**Section 3: Benefits and Applications**
* **Interviewer:** Kim Jaewook highlights the use case of identifying and tracking unread emails from a specific sender. What other potential applications can professionals envision for this tool? How can it enhance productivity and workflow?
* **Guest 1:** [Suggesting diverse use cases, such as tracking customer service emails, project updates, or crucial notifications from specific teams.]
* **Guest 2:** [Focusing on the impact on productivity, discussing how this automation can free up time for more focused tasks and reduce email overwhelm.]
**Section 4: Customization and Security**
* **Interviewer:**
The provided code allows for customization, like specifying the sender’s email address. What other aspects of this script can be modified to suit individual needs? Are there any security considerations users should be aware of?
* **Guest 1:** [Discussing possible customizations, such as filtering emails based on keywords, setting notification schedules, and adding personalized messages.]
* **Guest 2:** [Addressing security aspects, emphasizing the importance of securing API keys, managing permissions, and responsible use of Slack channels.]
**Section 5: Conclusion**
* **Interviewer:** Thank you both for your insightful perspectives. What final thoughts would you like to share with our audience regarding this innovative approach to email management?
* **Guest 1:** [Summarizing the key benefits and encouraging readers to explore the provided resources.]
* **Guest 2:** [Providing a call to action, inviting viewers to experiment with the code and leverage automation for improved workflow.]
**Outro:**
That concludes our discussion on automated email notifications with Google Apps Script and Slack. We hope this interview has provided valuable information and inspiration for streamlining your email management. For more details, please refer to the blog post by Kim Jaewook and explore the resources mentioned.