How to check if it’s an HTML email in JavaScript/Vue.js

in Code Write a comment

In this tutorial you’ll learn how to quickly check if returned email is an HTML email or not.

One of my Vue.js projects has a messaging section. Where users can send and receive messages (emails) internally as well as externally.

Users can read incoming messages. The app checks whether it’s an HTML email or not. If it’s an HTML email it will display this message as unescaped HTML in Vue.js template with a custom class.


Hi, I'm Renat 👋

 


Here’s how I coded it.

I’ve got an isHtmlEmail method that checks if the email starts with <!DOCTYPE string. HTML emails start with this tag.

isHtmlEmail(email) {
  return email.startsWith('<!DOCTYPE')
},

You can then add this condition to your template and render it as you wish.

<div v-if="isHtmlEmail" v-html="item.Text"></div>

If you find this post useful, please let me know and share your favourite filters in the comments below.

Cheers,
Renat Galyamov

Want to share this with your friends?
👉renatello.com/check-if-html-email-javascript

PS: You can also check how to get the first item in Vue.js arrayhow to add a class to body tag in Vue.jsHow to hide uncompiled mustache {{ code }} in Vue.js, How to use Vue.js filters inside the Vue instance and other Vue.js tutorials.

I developed a Vue.js starter kit that you can order today

Order Vue.js starter kit

Write a Comment

Comment