'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. I tried some javascript (fetch, XMLHttpRequest), but also came to know that all email clients do not support javascript. Is it right? Is there any options other than javascript?



Solution 1:[1]

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. Even the mail client must be able to work with 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.

Another way to fetch data/get mail info like statistics is to add a unique ID to all links used in the mail. 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. It's not ment for mails.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Lukas