简体   繁体   English

如何在 Email 模板中单击按钮触发 API 调用

[英]How to trigger an API call on a button click inside an Email Template

This is a use case where an API has to be triggered when the user clicks a button on his/her email. The API call should hit the server to do some action in backend.这是一个用例,当用户单击他/她的 email 上的按钮时,必须触发 API。API 调用应该命中服务器以在后端执行一些操作。 I tried some javascript (fetch, XMLHttpRequest), but also came to know that all email clients do not support javascript. Is it right?我尝试了一些 javascript (fetch, XMLHttpRequest),但也了解到所有 email 客户端都不支持 javascript。对吗? Is there any options other than javascript?除了 javascript 之外还有其他选项吗?

Most (nearly 99%) of mail clients and servers will put the mail with JS into spam or won't even let it into your inbox.大多数(将近 99%)的邮件客户端和服务器会将带有 JS 的邮件放入垃圾邮件中,甚至不会让它进入您的收件箱。 Even the mail client must be able to work with JS.即使是邮件客户端也必须能够使用 JS。 While in Outlook it can be enabled with plugins, you have to be 100% sure, that the receiver will receive it, otherwise you can`t do it.虽然在 Outlook 中它可以通过插件启用,但你必须 100% 确定接收方会收到它,否则你无法做到。

Another way to fetch data/get mail info like statistics is to add a unique ID to all links used in the mail.另一种获取数据/获取邮件信息(如统计信息)的方法是为邮件中使用的所有链接添加唯一 ID。 By chance, the user will click on it and you can work with the data on server side.偶然地,用户会点击它,你可以在服务器端处理数据。

But as allready mentioned: Don`t use JS in your mails.但正如前面提到的:不要在邮件中使用 JS。 It's not ment for mails.这不是邮件。

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

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