1
votes

Context

We are currently working on a short Apps script that sends links to Google Drive files (shared with anyone with the link) through the MailApp.sendEmail(options) function.

The script works well on our test G Suite domain but on the production domain, it just does not send the emails. There are no error messages.

Some code

The issue can be reproduced through the following pieces of code:

Code.gs file

function test_sendEmail() {
 
  const template = HtmlService.createTemplateFromFile('template.html');
  template.link = "https://drive.google.com";
  template.title = "This is a link";
  const mailBody = template.evaluate().getContent();
      
  console.log("Quota: " + MailApp.getRemainingDailyQuota()); /* Quota is not exceeded. */
  
  try {
    const options = {
      to: "myEmail@Address.com", /* Replace this with your email address */
      subject: "LINK",
      htmlBody: mailBody,
      noReply: true
    };
    
    MailApp.sendEmail(options);
  } catch(e) {
    console.log(e.message);
  }
}

template.html file

Link: <a href='<?= link ?>'><?= title ?></a>

What we tried

Emails are properly sent when the link does not contain the drive.google.com part. For example, emails with links to google.com are sent properly.

We are able to send an email from the Gmail account the script is executed as and this email is sent properly with the Drive links.

As opposite as this question, I do not get "Message blocked" email and using GmailApp.sendEmail instead of MailApp.sendEmail does not seem to change anything.

Finally, the script above works well in the test G Suite domains and in some others we tried.

Thus, I believe that it comes from the G Suite domain configuration that have specific restrictions on Apps script. Is it possible? Where can I change it in the G Suite admin console? What other points should I check to make it work?


More details on the issue:

  1. The script fail to send email both with G Suite, gmail and other email addresses.
  2. We tried in both Apps script runtime (V8 and legacy). Both doesn't work properly.
  3. I believe that SPF/DKIM/DMARC are not setup in the domain.
  4. We use the same test recipients in both G Suite environments.
  5. The code after the sendEmail method call is executed properly.
  6. The provided template was just an example to reproduce the issue. The real template looks like a typical email, with a list of links. It is not link-only.
  7. In the future, the script is supposed to send less than 100 emails per day. Right now, it is just sending a few test emails (not more than in test environment).
  8. We use the default cloud project associated with the script.
  9. The script is bound to a Google Sheets file.
  10. Below is the real template that we use.
Dear Customers,<br/><br/>
We inform you that new documents are available. Please find them below:
<ul>
<? for(let i = 0; i < docs.length; i++) { ?>
     <li>Document <a href='<?= docs[i].link ?>'><?= docs[i].title ?></a>, <i><?= docs[i].documentType ?></i> is available</li>
<? } ?>
</ul>
<br/>
Regards,<br/>
Your customer service.
1
Please bear in mind that emails that only include a link might be blocked by anti-spam features. Have you already tried to send the email to a Gmail / G Suite account? Have you already tried both runtimes? How are you calling the function? Does you domain already has setup SPF/DKIM/DMARC?Rubén
Grégoire, could you please provide moe info regarding the process of email sendout: when you say "the script above works well in the test G Suite domains" - do you use the same set o test recipients? Add a console.log or other statement of choice after the sendEmail method call - does the execution reach the line at all (my bet is on "it does")? Making emails delivered is a very tricky process, and your template, as Rubén mentioned, violates one of the rules that could classify it as suspicious - it is link-only (and smth tells me that Google sanitization measures might prevent bare DriveOleg Valter
Google's reaction to possible spam changes chaotically over time, so the absence of a "message blocked" email and no difference between those two API functions mean nothing. It could easily be the same vague and baffling issue.Brilliand
Thanks guys for your help. I edited the question to give you more details on the issue.Grégoire G.
@OlegValter, thanks for your help. Just added 9. and 10. with the real template.Grégoire G.

1 Answers

1
votes

Instead of MailApp use GmailApp (you might have to change the sendEmail parameters, check the docs)

The above because others have being reported similar problems, actually something similar happened recently to me while working on client's project.

Related