繁体   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

语境

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

该脚本在我们的测试 G Suite 域上运行良好,但在生产域上,它只是不发送电子邮件。 没有错误消息。

一些代码

该问题可以通过以下代码段重现:

代码.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);
  }
}

模板.html文件

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

我们尝试了什么

当链接不包含drive.google.com部分时,电子邮件会正确发送。 例如,带有指向google.com链接的电子邮件可以正确发送。

我们能够从 Gmail 帐户发送 email 脚本执行为,并且此 email 与驱动器链接正确发送。

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

最后,上面的脚本在测试 G Suite 域和我们尝试过的其他一些域中运行良好。

因此,我认为它来自对 Apps 脚本有特定限制的 G Suite 域配置。 可能吗? 我可以在 G Suite 管理控制台的哪里进行更改? 我还应该检查哪些其他点才能使其正常工作?


有关该问题的更多详细信息:

  1. 该脚本无法使用 G Suite、gmail 和其他 email 地址发送 email。
  2. 我们在两个应用程序脚本运行时(V8 和旧版)中都进行了尝试。 两者都不能正常工作。
  3. 我相信域中没有设置 SPF/DKIM/DMARC。
  4. 我们在两个 G Suite 环境中使用相同的测试收件人。
  5. sendEmail方法调用后的代码正确执行。
  6. 提供的模板只是重现问题的一个示例。 真正的模板看起来像一个典型的 email,带有一个链接列表。 它不是仅链接。
  7. 将来,该脚本应该每天发送少于 100 封电子邮件。 现在,它只是发送一些测试电子邮件(不超过测试环境)。
  8. 我们使用与脚本关联的默认云项目。
  9. 该脚本绑定到 Google 表格文件。
  10. 下面是我们使用的真实模板。
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.

代替 MailApp 使用 GmailApp(您可能必须更改 sendEmail 参数,检查文档)

以上是因为其他人被报告了类似的问题,实际上我最近在处理客户的项目时发生了类似的事情。

有关的

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM