Last active
May 31, 2023 13:02
Revisions
-
andrewmwilson revised this gist
Jul 29, 2015 . 1 changed file with 6 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,12 +15,12 @@ function sendEmailsToSlack() { Logger.log(message); var output = '*New Email*'; output += '\n*from:* ' + message.getFrom(); output += '\n*to:* ' + message.getTo(); output += '\n*cc:* ' + message.getCc(); output += '\n*date:* ' + message.getDate(); output += '\n*subject:* ' + message.getSubject(); output += '\n*body:* ' + message.getPlainBody(); Logger.log(output); var payload = { -
andrewmwilson revised this gist
Jul 29, 2015 . No changes.There are no files selected for viewing
-
andrewmwilson created this gist
Jul 29, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ // You will also need to create a gmail filter to add the 'send-to-slack' label // to any emails you want sent to slack function sendEmailsToSlack() { var label = GmailApp.getUserLabelByName('send-to-slack'); var messages = []; var threads = label.getThreads(); for (var i = 0; i < threads.length; i++) { messages = messages.concat(threads[i].getMessages()) } for (var i = 0; i < messages.length; i++) { var message = messages[i]; Logger.log(message); var output = '*New Email*'; output += '\nfrom: ' + message.getFrom(); output += '\nto: ' + message.getTo(); output += '\ncc: ' + message.getCc(); output += '\ndate: ' + message.getDate(); output += '\nsubject: ' + message.getSubject(); output += '\nbody: ' + message.getPlainBody(); Logger.log(output); var payload = { 'username': 'Monkeybot', 'text': output, 'channel' : '#some-channel', 'icon_emoji': ':hear_no_evil:', }; var options = { 'method' : 'post', 'payload' : Utilities.jsonStringify(payload), }; // replace this with your own Slack webhook URL // https://crowdscores.slack.com/services var webhookUrl = 'https://hooks.slack.com/services/****/****/****'; UrlFetchApp.fetch(webhookUrl, options); } // remove the label from these threads so we don't send them to // slack again next time the script is run label.removeFromThreads(threads); }