Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function main() {
const data = GmailApp.search('label:to_radtech is:unread', 0, 100); //to_radtechを設定したラベル名に
var i = 0;
while (data[i]) {
var message = data[i].getMessages();
var p = 0;
while (message[p]) {
if (message[p].isUnread()) {
var content = "件名: " + message[p].getSubject() + "\n\n" + message[p].getBody();
if (content.length > 2000) {
content = content.substring(1900, -1);
content += "\n\n-- 文字数制限突破しそうなので切りますた --";
}
var name = message[p].getFrom();
if (name.length > 32) {
name = name.substring(30, -1);
name += "";
}
var option = {
"method": "post",
"payload": {
"username": name,
"content": content
}
};
UrlFetchApp.fetch("https://discordapp.com/api/webhooks/00000000/xxxxxxxxxxx", option); //DiscordのWebHook URL
}
p++;
}
data[i].markRead();
i++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.