Try for free Book a demo

Logic App Best Practices, Tips, and Tricks: #25 How to send a well-formatted custom HTML Email

Microsoft Azure

4 Mins Read

Welcome again to another Logic Apps Best Practices, Tips, and Tricks. In my previous blog posts, I talked about some of the essential best practices you should have while working with Azure Logic Apps. Check out these Logic App tips and tricks!

Today I will speak about another important Best practice, Tips, and Tricks that you must consider while designing your business processes (Logic Apps): How to send a well-formatted custom HTML Email.

send html email from logic app

How to send a well-formatted custom HTML Email inside Logic Apps

Designing HTML emails for outlook is definitely not a simple task.  Outlook is designed to support only a subset of HTML 4, so some HTML tags are ignored. These tags are not removed from your code, they may be displayed just fine on other email clients that support them, but Outlook skips them. Moreover, Outlook does not read CSS, so you must use inline CSS.

But, assuming that you have a proper HTML “template” that will render properly inside Outlook or any other email client. The next question is: how can we send HTML emails inside Logic Apps?

Depending on the action and the connector that we will be using, there may be several ways to achieve this. For example, some time ago, there was an action inside the Outlook Connector called Send an Email – it is now deprecated, and you cannot see it anymore. On that action, we could put the custom HTML code on the Body property and define that the email body format would be HTML by setting the property Is HTML to true, and that would do the trick. Quite simple to use and efficient.

Sending HTML email from outlook

However, Send an email (V2) action – the currently available action on the Outlook connector – has a totally different behavior. First of all, it owns fewer properties:

  • The Is HTML property was removed from this action.
  • And a completely new look and feel of the Body property.

Sending HTML email from outlook

But if we do a simple test and try to put the HTML email directly on the Body:

send html email from logic app

We will rapidly realize that we no longer have the possibility – without a few tricks – to directly insert HTML code into the body property of the message as we did earlier with the previous version because that will result in us receiving an email full of HTML code on the body as plain/text:

send html email from logic app

Once again, this behavior may change based on the action and connector that you will be using. So the second question is: Is there a uniform way to send a well-formatted custom HTML Email inside our Logic Apps?

Yes, there is! And this approach will work regardless of the action and connector that you will be using. The solution is to build the HTML in a beforehand action that may be a composite action or in a variable. And then, put the compose output or variable value as the send mail body property, and the action will correctly render the output as an HTML.

To do that, we will need to:

  • On the Logic App designer, add the next step by clicking the +New step button
  • On the Choose an action window, enter Variables and select the action Initialize variable
  • On the Variable action configuration:
    • On the Name property, type EmailBody
    • On the Type property, specify the type as String
    • On the Value property, leave it blank
Logic App Designer
  • On the Logic App designer, add the next step by clicking the +New step button
  • On the Choose an action window, enter Variables and select the action Set variable
  • On the Variable action configuration:
    • On the Name property, select the EmailBody variable
    • On the Value property, type your custom HTML
Designing HTML email in Logic App

Note: You can take, for example, this fancy HTML Template I created for this article here and not the basic HTML code that you see in the picture above.

  • And then define directly on the Body editor (without switching to Code View) that the body will be the content of the variable we created earlier:
send html email from logic app

And you will see that we will receive a well-formatted HTML email in our mailbox:

send html email from logic app

I hope you enjoy this developer tip and stay tuned for the following Logic App Best practices, Tips, and Tricks.

Related reading

This article was published on Mar 10, 2023.

Azure Logic Apps - Request Demo CTA

Related Articles