'spring email buttons not working
I want to send a email message, Will have 1 link to load image from a url.
Then 2 buttons. one button to re direct to google.com and one link to redirect cnn.com
@Autowired
public JavaMailSender emailSender;
MimeMessage message = emailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message, true);
helper.setTo("[email protected]");
helper.setSubject("Test subject");
String googleLink="http://google.com";
String cnnLink="http://cnn.com";
String emailContent="\r\n" +
"<html>\n" +
" <body> \n" +
" <div align='center'>\n" +
" <div style='text-align:center;'>\n" +
" <IMG src='https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png' height='75' width='150'>\n" +
" </div>\n" +
" \n" +
" <br/><br/>\n" +
" Would you like to take it?<br/><br/><br/> \n" +
" <br/> \n" +
" <input type=\"button\" id=\"acceptAcct\" onclick=\"location.href='"+googleLink+"';\" style=\"width:10em;height:5em\" value=\"Click to load google\" /> \n" +
" <input type=\"button\" id=\"rejectAcct\" onclick=\"location.href='"+cnnLink+"';\" style=\"width:10em;height:5em\" value=\"Click to load CNN\" /> \n" +
" </div>\n" +
" \n" +
" </body>\n" +
" </html>\n";
helper.setText(emailContent, true);
message.setContent(message, "text/html");
emailSender.send(message);
I copy the html printed out to a simple test.html and it works well in my browse.
But when the email is recieved, i try clicking the button nothing happens. In the email ,when i use chrome debug to see the code, the input buttons are like below.
<input type="submit" id="m_-5702442034034898245acceptAcct" style="width:10em;height:5em" value="Click to load google">
<input type="submit" id="m_-5702442034034898245rejectAcct" style="width:10em;height:5em" value="Click to load cnn">
1). The id is differnt, i dont know where the numbers came from.
2.) The onclick=\"location.href='"+googleLink+"';\" are not there as part of input button.
Solution 1:[1]
There are significant limits on the type of html you can use in an email message, and every mail client will impose different limits. Generally, these limits aren't documented, but this might help you get started.
Solution 2:[2]
try this:"<a href= '"+googleLink+"' > \n"+ " <input type=\"button\"style=\"width:10em;height:5em\" value=\"Click me to accept\" /> \n" + "</a>\n"+
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 | Bill Shannon |
| Solution 2 | aziz hammami |
