+ Start a Discussion

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



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,




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.




Content-Type: multipart/alternative;