Reputation: 1622
I am attempting to make my own version of Boomerang, a script that returns emails to your inbox at a later time as specified by the user.
I am using Google Apps Script and I have everything working except I can't return the email to the top of the inbox. I've tried forwarding the email with the relevant script, but to no avail.
Any thoughts?
Here's a few examples of the code I've tried (none of which produce the result I'm looking for):
messages = GmailApp.getMessagesForThreads(threads);
for (var i = 0 ; i < threads.length; i++) {
messages[i][0].reply("<b>This message has been moved to the top of your inbox per your request. Please take action soon.</b>", {
replyTo: "[email protected]"
});
}
messages = GmailApp.getMessagesForThreads(threads);
for (var i = 0 ; i < threads.length; i++) {
forward("[email protected]", {
htmlBody: "<b>This message has been moved to the top of your inbox per your request. Please take action soon.</b>",
name: "ServAce85",
replyTo: "[email protected]",
from: "[email protected]",
subject: "Re: " + messages[i].getSubject()
});
}
messages = GmailApp.getMessagesForThreads(threads);
for (var i = 0 ; i < threads.length; i++) {
messages[i][0].forward("[email protected]", {
subject: messages[i][0].getSubject()
});
}
function moveEmail(threadsToMove) {
var threads = threadsToMove;
var messages = GmailApp.getMessagesForThreads(threads);
for (var i = 0 ; i < threads.length; i++) {
messages[i][0].forward(Session.getActiveUser().getEmail(), {
subject: "Re: " + messages[i][0].getSubject(),
htmlBody: "<b>This message has been moved to the top of your inbox per your request. Please take action soon.</b></n>" + Session.getActiveUser().getEmail() + "</n>" + messages[i][0].getBody()
});
GmailApp.sendEmail(Session.getActiveUser().getEmail(), "Re: " + messages[i][0].getSubject(), messages[i][0].getPermalink());
}
}
Upvotes: 1
Views: 697
Reputation: 1
I came here to look for a solution on something similar as Pause inbox.
Made this of it:
1) Make a filter in Gmail so every new mail bypasses the inbox and gets labeled as a custom label you created.
2) Make timetriggers for following google script function:
function moveTheMails(){
var label0 = GmailApp.getUserLabelByName("Custom Label/Sublabel if wanted");
var threads = label0.getThreads();
for (var i = 0; i < threads.length; i++) {
threads[i].moveToInbox();
threads[i].removeLabel(label0);
}
}
Voila, dependend on your timetriggers your new mails get delivered to your inbox at the custom times. As gmail-filter I used: from:(-{[email protected] OR [email protected]}) to:([email protected] OR [email protected]) The adresses in from are excluded (-) in the filter so mails from that persons are directly delivered in the inbox.
Upvotes: 0
Reputation: 291
This seemed to work for me:
function moveEmail() {
var threads = GmailApp.getInboxThreads(0, 2); // Change to what you want the threads to be
var messages = GmailApp.getMessagesForThreads(threads);
for (var i = 0 ; i < threads.length; i++) {
messages[i][0].forward("[email protected]", {
htmlBody: "<b>This message has been moved to the top of your inbox per your request. Please take action soon.</b></n>" + messages[i][0].getBody()
});
}
}
Upvotes: 1