I have found this question that is answered:
How can I automatically forward Gmail emails when a label is applied?
However I'm using that exact script and have replaced the label and recipient with my information, and it works intermittently, if at all.
I've tried formatting the label text string differently, changing the interval from 5 minutes to 1 minute and back, and if it does work, it misses a lot.
One note: I took out the "+'after:' +timeFrom" snippet and ran it once, and it was forwarding everything in the folder before it gave me a server error (which is understandable, there are about 6600 messages in the label) so I'm wondering if it might have something to do with the timing coding?
Another note is that I'm trying this on a G Suite email, rather than a regular Gmail account, so I'm not sure if that would affect anything.
Here's what I have currently:
function autoForward() {
var label = 'Questionnaires/Agent Logins';
var recipient = '[email protected]';
var interval = 5; // if the script runs every 5 minutes; change otherwise
var date = new Date();
var timeFrom = Math.floor(date.valueOf()/1000) - 60 * interval;
var threads = GmailApp.search('label:' + label + ' after:' + timeFrom);
for (var i = 0; i < threads.length; i++) {
threads[i].getMessages()[0].forward(recipient); // only the 1st message
}
}
I've tried reformatting the "label" variable to be:
Questionnaires/Agent_Logins
questionnaires-agent-logins
, which is the format you see in the Gmail search bar when viewing the label.
I'm somewhat familiar with javascript and the general logic of programming, so this code more or less makes sense to me, and I don't see why it would be having trouble.
I would really really appreciate any help with this, as it could save my boss up to 3 hours a day if I could automate this for him.
P.S. I also have tried the IFTTT recipe mentioned and no dice either.