Search code examples
emailgoogle-apps-scriptgmail

MailApp.sendEmail method doesn't get through to accounts with URL in the body - Message Blocked


I am working on Google Apps Script. I am trying to send email as follows:

function test_sendmail(){
  var subject = "subject";
  var body = "https://www.google.com/";
  var emailBody = body;
  var options = {
    htmlBody: body
  }

  var recipient = "[email protected]";

  MailApp.sendEmail(recipient, subject, emailBody, options);
}

"[email protected]"(email address A) is not valid, but it's only for showing you an example. I use a real email address in the GAS execution.

The GAS execution is run by another G-suite domain google account(email address B) by which account the code is written.

The email address A has editing rights to the spreadsheet that has the above code in the GAS editor.

But, the email from the above function doesn't get through the email address A. I got this email in the email address B.

enter image description here

LEARN MORE: https://support.google.com/mail/answer/6596?visit_id=637267406328019079-2003975007&rd=1

Then, I replace the email address with the email address B. and I tried to send it, and it did get through successfully.

Secondly, I changed the URL part:

var body = "https://www.google.com/";

to:

var body = "";

Then, the email successfully get through to both email addresses A and B.

The results listed as below:

enter image description here

The failure of sending email with URL to email address like the email address A has occurred recently like from 1 week or 2 weeks ago. Until then, the 4 cases had been successfully done before. I have no idea why this started happening recently.

I checked if the sender email address B is in the contact list of the recipient email address A.

It is not in my contacts. enter image description here

But when I searched it, it appeared, so it seems in all contacts.

enter image description here


Added 1: I tried sending email to the email address C which is another G-suite mail address in the same domain as the email address B, but email address C doesn't have rights to the spreadsheet and the editor.

It sent to the email C successfully even it has no right to the spreadsheet.


Added 2: I tried sending email to the email address D which is other email address that is neither G-suite domain or @google.com address. The result is the same as the email address A.



Solution

  • Gmail anti-spam algorithms are complex. To prevent that the messages sent by your script being blocked by them, follow the guidelines on Prevent mail to Gmail users from being blocked or sent to spam


    Possible Workaround

    One of my clients had the same issue, I replaced MailApp.sendEmail(message) by GmailApp.sendEmail(recipient,subject,body,options) apparently this worked (No bounce messages after 10 minutes)

    Rafa Guillermo added in a comment:

    Just want to add that in this case if this is an ongoing issue you should get your admin to contact G Suite support

    If you hasn't access to G Suite Support I think that you could report this issue to Google by using Google Feedback (Open Gmail web UI > click the settings button (gear icon) > Send feedback)

    Related