Grégoire G.
Grégoire G.

Reputation: 809

Apps script does not send email containing links to Google Drive files on a given G Suite domain, no error message

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: "[email protected]", /* 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.

Upvotes: 1

Views: 821

Answers (1)

Wicket
Wicket

Reputation: 38160

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

Upvotes: 1

Related Questions