Skip to content

Instantly share code, notes, and snippets.

@soup-bowl
Created February 22, 2023 20:50
Show Gist options
  • Save soup-bowl/f1928b2470a115cb587a1776ea595c2e to your computer and use it in GitHub Desktop.
Save soup-bowl/f1928b2470a115cb587a1776ea595c2e to your computer and use it in GitHub Desktop.
ReviveToday closed inbox auto-reply
function autoReply() {
var label = GmailApp.getUserLabelByName("AutoReply");
var threads = GmailApp.search('label:inbox label:unread to:admin@revive.today');
var sender = "admin@revive.today";
var senderName = "ReviveToday Do Not Reply";
var message = "Hello,<br><br>Thank you for your email. Unfortunately, due to a high level of spam and malicious emails this inbox is now closed.<br><br>The following are now the alternative options:<ul><li>For discussions on all things retro, please consider joining the <a href='http://revive.today/discord'>ReviveToday Discord</a>.</li><li>For website matters, please use the <a href='http://revive.today/contact'>Contact form</a>.</li></ul><br><br>Kind regards,<br>ReviveToday Team";
var subject = "Auto-Reply: Discontinued Inbox";
for (var i = 0; i < threads.length; i++) {
var thread = threads[i];
var messages = thread.getMessages();
for (var j = 0; j < messages.length; j++) {
if (messages[j].getTo() == sender) {
var email = messages[j].getReplyTo();
if (!email) {
email = messages[j].getFrom();
}
GmailApp.sendEmail(email, subject, message, {from: '"' + senderName + '" <' + sender + '>', htmlBody: message});
//var replyMessage = messages[j].createReply("", {from: sender, htmlBody: message});
//replyMessage.send();
}
}
thread.addLabel(label);
}
}
@soup-bowl
Copy link
Author

This was built with significant assistance from ChatGPT.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment