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:
Sending Emails - CUBA Platform. Developer’s Manual

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:
Budding Developer's Ground: Sending HTML (as) Mail through Java (Spring)

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:
HTML minifier
to minimize it, make sure it starts with …

-Mike