简体   繁体   English

应用程序脚本不发送 email 包含指向给定 G Suite 域上的 Google Drive 文件的链接,没有错误消息

[英]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.我们目前正在开发一个简短的应用程序脚本,该脚本通过MailApp.sendEmail(options) function 发送指向 Google Drive 文件的链接(与知道该链接的任何人共享)。

The script works well on our test G Suite domain but on the production domain, it just does not send the emails.该脚本在我们的测试 G Suite 域上运行良好,但在生产域上,它只是不发送电子邮件。 There are no error messages.没有错误消息。

Some code一些代码

The issue can be reproduced through the following pieces of code:该问题可以通过以下代码段重现:

Code.gs file代码.gs 文件

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模板.html文件

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

What we tried我们尝试了什么

Emails are properly sent when the link does not contain the drive.google.com part.当链接不包含drive.google.com部分时,电子邮件会正确发送。 For example, emails with links to google.com are sent properly.例如,带有指向google.com链接的电子邮件可以正确发送。

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.我们能够从 Gmail 帐户发送 email 脚本执行为,并且此 email 与驱动器链接正确发送。

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.这个问题相反,我没有收到“消息被阻止”email 并且使用GmailApp.sendEmail而不是MailApp.sendEmail似乎没有任何改变。

Finally, the script above works well in the test G Suite domains and in some others we tried.最后,上面的脚本在测试 G Suite 域和我们尝试过的其他一些域中运行良好。

Thus, I believe that it comes from the G Suite domain configuration that have specific restrictions on Apps script.因此,我认为它来自对 Apps 脚本有特定限制的 G Suite 域配置。 Is it possible?可能吗? Where can I change it in the G Suite admin console?我可以在 G Suite 管理控制台的哪里进行更改? 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.该脚本无法使用 G Suite、gmail 和其他 email 地址发送 email。
  2. We tried in both Apps script runtime (V8 and legacy).我们在两个应用程序脚本运行时(V8 和旧版)中都进行了尝试。 Both doesn't work properly.两者都不能正常工作。
  3. I believe that SPF/DKIM/DMARC are not setup in the domain.我相信域中没有设置 SPF/DKIM/DMARC。
  4. We use the same test recipients in both G Suite environments.我们在两个 G Suite 环境中使用相同的测试收件人。
  5. The code after the sendEmail method call is executed properly. sendEmail方法调用后的代码正确执行。
  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.真正的模板看起来像一个典型的 email,带有一个链接列表。 It is not link-only.它不是仅链接。
  7. In the future, the script is supposed to send less than 100 emails per day.将来,该脚本应该每天发送少于 100 封电子邮件。 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.该脚本绑定到 Google 表格文件。
  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.

Instead of MailApp use GmailApp (you might have to change the sendEmail parameters, check the docs)代替 MailApp 使用 GmailApp(您可能必须更改 sendEmail 参数,检查文档)

The above because others have being reported similar problems, actually something similar happened recently to me while working on client's project.以上是因为其他人被报告了类似的问题,实际上我最近在处理客户的项目时发生了类似的事情。

Related有关的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何向外部发送 G-Suite/Workspace 别名域的电子邮件(例如通过 Ubuntu) - How to send email of a G-Suite/Workspace alias domain externally (e.g. via Ubuntu) Google Apps脚本-通过电子邮件发送pdf - Google Apps Script - send pdf in email smtplib 电子邮件不发送,脚本继续运行,没有错误消息 - smtplib email does not send, script keeps running with no error message 尝试使用 phpmailer 和 g-suite 发送电子邮件 - Trying to send email with phpmailer and g-suite 如何使用NodeJS安全发送G Suite电子邮件? - How to send G Suite email securely with NodeJS? 包含重定向到黑名单域的链接的电子邮件 - Email containing links that redirect to a blacklisted domain Google脚本发送包含工作表中值的电子邮件 - Google Script to Send Email containing values from Sheet Google Apps 脚本:发送 PDF 而不是 email 中的 zip 文件 - Google Apps Script: Send PDF instead of .zip file in email smtp 中继 - g 套件 - 带有自定义域电子邮件的 gmail - smtp relay - g suite - gmail with custom domain email 尝试自动发送通过应用程序脚本创建的 Google 文档的电子邮件 - Trying to send email automatically of a Google Docs created through apps script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM