Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
August 19, 2022 03:46 pm GMT

GMAIL to Discord Channel Webhook Tutorial

Abstract

Slack, Microsoft Teams, Discord .

, Discord .

Discord .

Discord DOCs : https://discord.com/developers/applications

Prerequisite

  • Discord

Image description

Getting Started

Integrations Webhooks

Integrations

Image description

New Webhook Webhook (Bot Name, Channel) Noti-Bot

Discord

Webhook

Image description

:
https://www.google.com/script/start/

Image description

Image description

Note

  • webhooks Discord Webhook URL
Webhook

Image description

  • channel
Discord

Image description

  • searchQuery . ( )
Gmail

Image description

  • Gmail Discord 2000 2000 .
code.gs
function postDiscord(postMessage) {    const webhooks = 'https://discord.com/api/webhooks/webhooks/{webhook.id}/{webhook.token}';    const channel = '{channel name}';    const parse = 'full';    const method = 'post';    const payload = {        channel: channel,        content: postMessage,        parse: parse,    };    const params = {        method: method,        payload: payload,        muteHttpExceptions: true,    };    response = UrlFetchApp.fetch(webhooks, params);}function sendMailsToDiscord() {    const searchQuery = '{gmail query}';    const date = new Date();    const checkSpan = 30;    date.setMinutes(date.getMinutes() - checkSpan);    const threads = GmailApp.search(searchQuery);    const msgs = GmailApp.getMessagesForThreads(threads);    for (let i = 0; i < msgs.length; i++) {        const lastMsgDate = threads[i].getLastMessageDate();        if (lastMsgDate.getTime() < date.getTime()) break;        for (let j = 0; j < msgs[i].length; j++) {            const msgDate = msgs[i][j].getDate();            const msgBody = msgs[i][j].getPlainBody();            const subject = msgs[i][j].getSubject();            const postMessage =                'From mailing list' +                '
' + Utilities.formatDate(msgDate, 'America/New_York', 'MM/DD/yyyy hh:mm:ss') + '
' + 'Title:' + subject + '
' + '[hr]' + msgBody; // 2000 Characters limits if (postMessage.length > 2000) { const stopPos = 1900; // const msg = '"Exceeded 2000 character limit."'; postMessage = postMessage.substring(0, stopPos) + '
' + msg; } postDiscord(postMessage); } }}

trigger

.

Note

  • : sendMailsToDiscord
  • : Head
  • :
  • :
  • : 30
  • :
trigger

Image description

Conclusion


GMAIL Discord webhook Google App Script Set up .

Discord . GMAIL Webhook .

Method Google App Script

Link: https://developers.google.com/apps-script/reference/document


Original Link: https://dev.to/soom/gmail-to-discord-channel-webhook-tutorial-mnm

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To