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:
- The script fail to send email both with G Suite, gmail and other email addresses.
- We tried in both Apps script runtime (V8 and legacy). Both doesn't work properly.
- I believe that SPF/DKIM/DMARC are not setup in the domain.
- We use the same test recipients in both G Suite environments.
- The code after the
sendEmail
method call is executed properly. - 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.
- 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).
- We use the default cloud project associated with the script.
- The script is bound to a Google Sheets file.
- 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.
console.log
or other statement of choice after thesendEmail
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 Drive – Oleg Valter