如何每次发送包含嵌入式链接到Web应用程序的嵌入式链接的草稿时,如何阻止请求出去Doget(e)? (Google Apps脚本)
Hello Stackoverflowers和其他地球的其他伟大居民,以及其他!
编辑: 同样的问题仍然是相关的,但是经过更多的反复试验 - 我发现我的所有脚本都相同。似乎行为不同的一种只是向其他人发送草稿的速度要快,而这样做是“要求” doget()一次处理太多请求,因此在大多数情况下都没有执行。但是,发送草稿仍触发了请求。
我的目标是将URL嵌入DOGET()Web应用程序(使用GAS构建)的电子邮件中 - 只有在单击时,它才能识别电子邮件的收件人,这要归功于某些独特的用户串作为所述URL的参数。
这就像魅力一样。当嵌入式链接在电子邮件主体内单击时>它触发了将这些参数的剩余参数触发的Web应用程序。
重要的是要注意!我有两个执行相同操作的脚本,请遵循相同的程序将URL嵌入电子邮件主体,并且它们都起作用。
两者都使用气体与此嵌入式URL创建草稿,使用:
var url_to_webapp = 'https://script.google.com/macros/s/AKf...VJ/exec?to=<email_address>&userID=<userID>&removalCode=<removalCode>'
var html = some html...
var htmlBody = html + url_to_webapp // 'url_to_webapp' gets converted by Gmail to a <a href ...>
var draft = GmailApp.createDraft(EmailAddress, emailSubject, msgBody, {
from: thisAlias,
name: name,
replyTo: thisAlias,
htmlBody: htmlBody
});
var draftID = draft.getId();
参数用“ EncoDeuricomponent(userId.replace(/'/g,“”)“类型行。
,在其中一个脚本时,Web应用程序也获取请求,我使用的分钟:
var draft = GmailApp.getDraft(draftID);
draft.send();
然后,它触发了Web应用程序逻辑。
我想发生的事情是,只有单击嵌入式链接&gt;&gt; Web应用程序获取请求。不是在发送草稿时。
同样,它不会发生其他脚本,该脚本使用相同的代码生成相同格式的URL(来自其他项目上的其他Web应用程序),并从同一Gmail帐户发送草稿。
在阅读了很多之后,我尝试了:
- 复制电子表格和附加的脚本多次
- 禁用条纹(这还跟踪了从Gmail发送的电子邮件)。
- 检查外向链接。我发现,当草稿创建时, 甚至在发送之前,在我嵌入的URL代码Gmail添加了一个 “ ... data-saferedirecturl =” https://www.google.com/url?q=https://script.google.com/macros/macros/s/akf.....p...p.source=gmail&Amp; ; usg = aovvaw1p-l0mcxazu1pyimsrufks” 到HREF,这意味着它将我的脚本发送到Google搜索?
- 我确认在粘贴 “ https://www.google.com/url?q=https://script.google.com/macros/s/akf” 进入浏览器地址行,按Enter确实触发了 请求及其Web应用程序。无论如何,我不明白为什么 添加此部分,如何停止此部分或这是原因。但 当相同的附录代码为时,我的其他脚本不会触发 在发送时,还增加了出发的草稿。
- 我尝试使用相同的逻辑来跟踪电子邮件开口,通过嵌入 具有较少参数的跟踪标签,该标签也使用气体 WebApp与Doget(e)一起查找人们何时打开我们的电子邮件&gt;&gt; 同样的事情仍然发生。这意味着Web应用程序获取请求 当发送电子邮件时,然后再次发送电子邮件 打开。这给出了线索,因为意思是这是 至少在某些情况下,预期的行为。
- 当我用相同的代码生成草稿时,但手动发送 通过使用Gmail的GUI单击草稿中的“发送” -WebApp 不会触发。仅当调用“ draft.send()”时,网络 应用程序获取请求并处理。
因此,基本上,我的问题归结为: 如何防止此不需要的请求到达我的Web应用程序,或者是什么可能导致我的一个脚本导致Gmail草稿在发送时不会触发Web应用程序(这是所需的行为)。
PS首次在这里询问,感谢任何能提供帮助的人(对这个社区印象深刻,迫不及待地想帮助某人!)
Hello stackoverflowers and other great inhabitants of planet Earth, and beyond!
EDIT:
Same issue is still relevant, but after more trial and error - I found out that ALL of my scripts act the same. The one that seemed to behave differently was just SENDING DRAFTS FASTER than the others, and in doing so it was 'asking' doGet() to handle too many requests at once, hence it was not executing on most occasions. but still, sending the draft triggered a request.
My goal is to embed a url to a doGet() web app (built with GAS) inside an email message - which ONLY WHEN CLICKED will identify the email's recipient, thanks to some unique user-strings included as parameters of said url.
This works like a charm. When the embedded link is clicked inside the email body >> it triggers the web app which takes those parameters does the rest.
Important to note! I have two scripts that do the same thing, follow the same procedure to embed the url in the email body and they both work.
Both use GAS to create a draft with this embedded url, using:
var url_to_webapp = 'https://script.google.com/macros/s/AKf...VJ/exec?to=<email_address>&userID=<userID>&removalCode=<removalCode>'
var html = some html...
var htmlBody = html + url_to_webapp // 'url_to_webapp' gets converted by Gmail to a <a href ...>
var draft = GmailApp.createDraft(EmailAddress, emailSubject, msgBody, {
from: thisAlias,
name: name,
replyTo: thisAlias,
htmlBody: htmlBody
});
var draftID = draft.getId();
Parameters are encoded with a "encodeURIComponent(UserID.replace(/'/g, "")" type line.
However, when it comes to ONE of the scripts, the web app also gets a request the minute I use:
var draft = GmailApp.getDraft(draftID);
draft.send();
Which then triggers the web app logic - unwantedly.
What I DO want to happen is that only when the embedded link is clicked >> the web app gets a request. Not when the draft is sent.
Again, it doesn't happen with the other script, which uses the same code to generate the same format of url (from a different web app on a different project) and send the draft from the same Gmail account.
After reading quite a lot I tried:
- Duplicating the spreadsheet and the scripts attached several times
- Disabling Streak add on (which also tracks emails sent from gmail).
- Inspecting the outgoing link. I found that when the draft iscreated,
even before it's sent, AFTER my embedded url code Gmail adds a
"...data-saferedirecturl="https://www.google.com/url?q=https://script.google.com/macros/s/AKf...&source=gmail&ust=1656656998227000&usg=AOvVaw1p-L0mcxAZU1pyimSRufks"
to the href, meaning it sends my script to google search?! - I confirmed that when pasting the
"https://www.google.com/url?q=https://script.google.com/macros/s/AKf"
into the browser address line and pressing enter DOES trigger the
request and therefor the web app. Anyway, I can't understand why
this part gets added, how to stop this or if this is the cause. BUT
MY OTHER SCRIPT DOESN'T GET TRIGGERED when same appended code is
added to outgoing drafts, at the time of sending. - I tried to use the same logic to track email openings, by embedding
a tracking tag with less parameters, which also uses a GAS
webapp with a doGet(e) to find out when people open our emails >>
and same thing still happens. Meaning the web app gets a request
when the email is sent, and then once again when the email is
opened. This gives a clue, because the meaning is that this is an
intended behavior, at least in some situations. - When I generate the draft with the same code, but send it manually
by clicking "Send" in the draft using Gmail's gui - the webapp
doesn't get triggered. Only when 'draft.send()' is called, the web
app gets a request and handles it.
So basically, my question boils down to:
How to prevent this unwanted request from reaching my web app, or what could cause ONE of my scripts to result in Gmail drafts that DO NOT trigger the web app when sent (which is the desired behavior).
p.s. first time asking here, thanks to anyone who can help (very impressed with this community, can't wait to help someone!)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如上一篇评论所述,您可以转到 google does dorese dorese deasade tracker 应用程序脚本组件创建问题。
这是它的组件模板:
As mentioned on the last comment, you can go to Google Issue Tracker and on the Apps Script component create an issue.
This is the component template for it: