How to send email with html content

Hi there,
I am able to send gmail with (smtp has been correctly configured in app.properties):
EmailInfo emailInfo = new EmailInfo( "myTestEmail@gmail.com", //recipients
"Send text email via Cuba", // subject
"Sending regular text email works fine."); //email content
emailService.sendEmailAsync(emailInfo);

Of cause followed Cuba manual:
https://doc.cuba-platform.com/manual-6.1/sending_emails_recipe.html?_ga=1.9771698.68555209.1461843979

Now I would like to send gmail with html content. As a test, I simply replaced the email content above to:
"

This is an test html email.

";
and I received:

This is an test html email.

Apparently html content is not rendered.

I found this article using MimeMessage to send html email:
http://learndevelopingmyway.blogspot.com/2012/09/sending-html-as-mail-through-java-spring.html

I have not tried personally. But just wondering if Cuba platform support html email? If yes, any code snippet or example would be much appreciated.

-Mike

Hi,

in the code of the platform you’ll find the following method to determine the the content body type from the body of the email:
EmailSender. getContentBodyType. As you see in line 114 there is a check if the content starts with a html tag: <html>. In this case it will handle the body as html and set the correct content type afterwards.

So you should probably just add the tag and it will work.

Bye,
Mario

1 Like

It works like a charm. Thanks Mario for the swift reply.

I followed your instructions. Since my html email content is lengthy, I use an online tool:
https://kangax.github.io/html-minifier/
to minimize it, make sure it starts with …

-Mike