I get an automated email when an event occurs, but need to be notified if it isn't received. It's easy to overlook something that doesn't happen.
Here's what I have, but the var c remains 0 when script ends (I'm expecting it to not be 0 if email is found, and be 0 and send email if subject is not found.
function CheckForSubjectInEmail() {
var threads = GmailApp.search("in:Inbox");
var subject = "Testing";
var c = 0;
for (var i = 0; i < threads.length; i++) {
var messages = threads[i].getMessages();
for (var m = 0; m < messages.length; m++) {
var msg = messages[m].getSubject();
// Does the message subject match?
if (msg = subject) {
c = c++
}
if (c = 0) {
MailApp.sendEmail("email@domain.com",
"Important email not received.",
"The Testing email has not yet been received.");
}
}
}
}
Cheers, Dave