简体   繁体   English

通过 Google Apps 脚本发送 email 时出现问题

[英]Problem in sending email by Google Apps Script

I have been sending Email by Google Apps Script successfully for sometimes.有时,我一直通过 Google Apps 脚本成功发送 Email。 However, when I open a new Google Workspace account and use the same code to send the same things to the same receiver, the new account does not work.但是,当我打开一个新的 Google Workspace 帐户并使用相同的代码将相同的东西发送给同一个接收者时,新帐户不起作用。 I get a message of "Message blocked" from mailer-daemon@googlemail.com.我收到来自 mailer-daemon@googlemail.com 的“消息被阻止”消息。 It does not show any error description.它不显示任何错误描述。 When I send this message again in Gmail, the message can successfully reach the receiver.当我在 Gmail 中再次发送此消息时,消息可以成功到达接收者。 Any idea?任何想法? Things are perfectly fine in my old Google accounts but not OK in any Google accounts I tried this month.在我的旧 Google 帐户中一切都很好,但在我本月尝试的任何 Google 帐户中都不好。

function myFunction() {
  MailApp.sendEmail("xxx@gmail.com","From yyy","Hello!");  
}

TL;DR: TL;博士:

Gmail thinks you are a spammer. Gmail 认为您是垃圾邮件发送者。 Changing MailApp for GmailApp should work.更改GmailAppMailApp应该可以工作。 In your case:在你的情况下:

GmailApp.sendEmail("xxx@gmail.com","From yyy","Hello!");

Full answer:完整答案:

The reason this is happening is because Gmail is flagging your email as a possible spam.发生这种情况的原因是因为 Gmail 将您的 email 标记为可能的垃圾邮件。 This is likely because it is a new account, the contents of the message and configuration (like sending only plain text, no replyTo or noReply configuration, etc.).这很可能是因为它是一个新帐户,消息的内容和配置(比如只发送纯文本,没有replyTonoReply配置等)。 The Google algorithm is probably quite complex and there is no clear way of testing it.谷歌算法可能相当复杂,没有明确的测试方法。 Here is an article talking about how to prevent being blocked .这是一篇关于如何防止被阻止的文章

Other people that had this problem seem to have success using GmailApp instead of MailApp ( Stack Overflow question 1 , Stack OVerflow question 2 ).其他遇到此问题的人似乎使用GmailApp而不是MailApp成功( 堆栈溢出问题 1堆栈溢出问题 2 )。 The reason is probably how the services internally work.原因可能是服务内部如何工作。

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

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