Search code examples
djangoemailhtml-emailemail-clientdjango-email

Can I send requests to the server from HTML rendered in email?


I am trying to implement the following functionality.

The server sends an email to a user who doesn't necessarily have an account in the server. In the email, the user is asked to rate a certain model (send a request to the server).

Can I make it in such a way that the user can click the button and doesn't get redirected to some other page, but sends the request directly to the server.

<div>
    <p> Hi {{ user }},  </p> 
    This e mail is to kindly ask you to rate {{ job_seeker }}, who previously
     worked with you.
     
 
    Please rate him from 1 to 3 below.
    
    <button onclick="some function that wont work in email">1</button>
    <button>2</button>
    <button>3</button>

 </div>

I am using django.


Solution

  • NO, you cant execute JavaScript in email templates.

    Due to serious security issues, most of the email clients block JavaScript from executing. that's why your redirection script doesn't work.

    the solution is to use an <a> tag with a URL that specifies the page link instead of <button>.