function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ClintLeeClintLee 

Email Services - Possible to determine if an Incoming Email is HTML or Plain Text?

Hello,

 

I have spent some time searching the forums and reviewing the docs on Email Services and cannot find an answer to this, so I'm hoping the smart folks here can help me out.

 

I have an email service set up that accepts incoming emails.  Is there a way to check an incoming email to determine whether it is in HTML or PlainText format?

 

For example, something like this:

 

if (email is in HTML format) {

   do this code using email.htmlBody;

 

} else {

   do this code using email.plainTextBody;

}

 

Thanks in advance,

 

Clint

 

Rasmus MenckeRasmus Mencke

There are a couple of things you can do, the easiest one is probably to just check and see if the HTML and/or Text version is null.

 

If you want to get more fancy, you can inspect the email headers and look for the "Content-type: " header and see if it is set to multipart. If it is set to just text/plain or text/HTML you would know. I would recommend doing a "null" check on the html & text version as that is pretty straight forward.

 

Example:

 

Content-Type: multipart/alternative;
	boundary="----=_Part_56_26296840.1280944082427"