Jmix version: 2.2.3
Jmix Studio plugin version: 2.2.4-241
IntelliJ IDEA 2024.1 (Ultimate Edition)
Hi Jmix team.
I’ve encountered problem with HTML format of email template. That is to say,
such kind of email I received.
String body = resources.getResourceAsString("template/email.html");
EmailInfo emailInfo = EmailInfoBuilder.create()
.setAddresses(tempUser.getEmail())
.setSubject("IOT Radiomer")
.setBody(body)
.build();
try {
emailer.sendEmail(emailInfo);
return true;
} catch (Exception e) {
log.warn("EmailService.sendEmail: {}", e.getMessage());
}
So, can you provide any solution to send email as a HTML format?
yarik1706
(Ярослав Горожанкин)
June 8, 2024, 2:40pm
2
Try to set bodyContentType as "text/html; charset=UTF-8". Or remove first string <!Doctype html> from body. becouse Emailer checks if body starts with "<html>"
protected String getContentBodyType(SendingMessage sendingMessage) {
String bodyContentType;
String text = sendingMessage.getContentText();
bodyContentType = text.trim().startsWith("<html>") ? "text/html; charset=UTF-8" : "text/plain; charset=UTF-8";
log.debug("Content body type is not set for email '{}' with addresses: {}. Will be used '{}'.",
sendingMessage.getSubject(), sendingMessage.getAddress(), bodyContentType);
return bodyContentType;
}
protected void replaceRecipientIfNecessary(SendingMessage msg) {
if (emailerProperties.isSendAllToAdmin()) {
String adminAddress = emailerProperties.getAdminAddress();
log.warn("Replacing actual email recipient '{}' by admin address '{}'", msg.getAddress(), adminAddress);
msg.setAddress(adminAddress);
if (msg.getCc() != null) {
msg.setCc(adminAddress);
}
if (msg.getBcc() != null) {
msg.setBcc(adminAddress);
}
3 Likes