MailApp.sendEmail Not Working?

I think I have an answer to my own question, which may be helpful to anybody else who has this problem. MailApp.sendEmail DOES, indeed, still seem to be working. What has changed is the way Gmail is handling certain types of messages.

If I use MailApp.sendEmail to send an e-mail to a third party, it'll get through, no problem. As pointed out by Fashtas, if I use MailApp.sendEmail to send an e-mail to the Gmail account that the spreadsheet belongs to, no problem.

Here's the problem: if I use MailApp.sendEmail to send the message to a third party account that automatically forwards BACK to the Gmail account that the spreadsheet belongs to, those messages no longer get through.

Therefore, in the sample code I posted above, the matt@.com e-mail address automatically forwards back to my Gmail account. The messages sent by the MailApp.sendEmail make it through to the .com mail server, but for some reason, they don't get forwarded back to my Gmail inbox. They appear in the Gmail Sent Items folder (presumably because they were sent by the Gmail account that the spreadsheet belongs to), but they never hit the inbox.

That behavior is new. In the past, there has been no problem with those messages getting forwarded from the *.com server to my Gmail inbox. I don't know what changed to cause the problem. And I don't know how to fix it.

But I, therefore, think the answer to my question is that MailApp.sendEmail IS working as designed.


As explained by doebtown, MailApp.sendEmail() will refuse to send messages to any address that forwards to your account. For example, if you (the spreadsheet's owner) belong to a group, [email protected], within your organization then mailApp.sendEmail() messages will not be delivered to [email protected]. That is, the following code will not send:

var email = '[email protected]';

var subject = 'The Week Ahead';

var body = 'Hi there!';

var htmlbody = "<p>Hi there!</p>";

// this will not send
MailApp.sendEmail(email, subject, body,{
  htmlBody : htmlbody
});

HOWEVER, you can work around this issue by appending your email to the addresses.

var email = '[email protected], [email protected]';

var subject = 'The Week Ahead';

var body = 'Hi there!';

var htmlbody = "<p>Hi there!</p>";

// this will send to your address and the full list
MailApp.sendEmail(email, subject, body,{
  htmlBody : htmlbody
});

This email will send to your address as well as to the list to which you belong. This is not a perfect solution, but is viable if you do not want to create a specific account for managing scripts.