Sending html email with css, js and images spring boot

Viewed 1184

I have to send html to email but it has styles, images and js. I have button which calls my service POST method and send there some information so I have to attach js file anyway. I use thymeleaf and I tried to connect syles using url addres (like th:href=@{"https://localhost:8080/css/style.css"}) but it doesn't work. So how can I attach my css, js and images to html email?

Method I want to call using button:

@PostMapping(USER_CONFIRMATION_ENDPOINT)
    public String getConfirmUserRegistrationPage(@Valid @RequestBody ConfirmRegistrationDto confirmRegistrationDto) {

        emailService.confirmUserRegistration(confirmRegistrationDto);

        return "/accountActivationPage.html";
    }

My EmailService method:

private void sendLetter(User user, String subject, String link, String templatePath) {
        Context context = new Context();
        context.setVariable("link", link);
        String htmlContent = templateEngine.process(templatePath, context);
        MimeMessage mimeMessage = javaMailSender.createMimeMessage();
        try {
            MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true, "UTF-8");
            message.setSubject(subject);
            message.setText(htmlContent, true);
            message.setTo(user.getEmail());
            message.setFrom(emailProperties.getFrom());
        }
        catch (MessagingException e) {
            e.printStackTrace();
        }

        javaMailSender.send(mimeMessage);
    }
0 Answers
Related