Fix email encodding problem.

This commit is contained in:
Paulo Gustavo Veiga 2022-03-30 07:50:42 -03:00
parent 641bcbbe17
commit accf252e78

View File

@ -26,7 +26,7 @@ import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper; import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.mail.javamail.MimeMessagePreparator; import org.springframework.mail.javamail.MimeMessagePreparator;
import javax.mail.internet.MimeMessage; import java.nio.charset.StandardCharsets;
import java.util.Map; import java.util.Map;
public final class Mailer { public final class Mailer {
@ -54,17 +54,14 @@ public final class Mailer {
public void sendEmail(final String from, final String to, final String subject, final Map<String, Object> model, public void sendEmail(final String from, final String to, final String subject, final Map<String, Object> model,
@NotNull final String templateMail) { @NotNull final String templateMail) {
final MimeMessagePreparator preparator = final MimeMessagePreparator preparator =
new MimeMessagePreparator() { mimeMessage -> {
public void prepare(MimeMessage mimeMessage) final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, StandardCharsets.UTF_8.name());
throws Exception { message.setTo(to);
final MimeMessageHelper message = new MimeMessageHelper(mimeMessage); message.setFrom(from);
message.setTo(to); message.setSubject(subject);
message.setFrom(from);
message.setSubject(subject);
final String messageBody = VelocityEngineUtils.mergeTemplateIntoString(velocityEngineWrapper.getVelocityEngine(), "/mail/" + templateMail, model); final String messageBody = VelocityEngineUtils.mergeTemplateIntoString(velocityEngineWrapper.getVelocityEngine(), "/mail/" + templateMail, model);
message.setText(messageBody, true); message.setText(messageBody, true);
}
}; };
this.mailSender.send(preparator); this.mailSender.send(preparator);