-1

I'm using MimeMessage setContent to send http body emails from my application.

MimeMessage message = new MimeMessage(sessionProps());
            message.setSender(addressFrom);
            message.setSubject(subject);
            message.setContent(template, "text/html;charset=UTF-8");

This template contains a button that calls my rest api (see code bellow).

<body>  
 .....
  <p>
        <button type="button" onclick="userAction()">Click Me!</button>
    </p>
    <script type="text/javascript">
    function userAction() {
        const response = fetch(restApi);
      const myJson = response.json(); //extract JSON from the http response
       alert(myJson);
    }
    </script>
    </body>

My simple rest

@GetMapping("/hello/")
    public void hello() {
        System.out.println("hello world");
    }

Unfortunately, when I click the button inside gmail body email nothing is showing, Any thoughts ? Thank you

HEssaidi
  • 33
  • 2
  • 8

1 Answers1

0

I found that email clients strip out javascript.

I'm afraid such functionality, while theoretically possible, wouldn't be very practical given that most email clients strip out or disable JavaScript in order to prevent malicious code execution or other security issues.

jQuery event not triggred in gmail

is JS supported by email clients

Dharman
  • 30,962
  • 25
  • 85
  • 135
HEssaidi
  • 33
  • 2
  • 8