I'm using a script to forward a long list of emails (under one label) to a new account. However, I'm hitting a exceeded maximum execution time error not even quarter way through. I was wondering if there was a workaround, maybe a possibility to store the variables on the sheet and resume after a set time? I'm not too well versed in coding so any help on this would be appreciated.
function forwardMail() {
var data = SpreadsheetApp.getActiveSheet().getRange("A2:B11").getValues();
for (i in data) {
var row = data[i];
var name = row[0].toString();
var email = row[1].toString();
var label = GmailApp.getUserLabelByName(name);
if (label && (email != "")) {
var threads = label.getThreads();
for (var x in threads) {
var messages = threads[x].getMessages();
for (var y in messages) {
var subject = messages[y].getSubject();
messages[y].forward(email, {
subject: subject});
}
threads[x].removeLabel(label);
}
}
}
}