+ 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,





spec for HTML email is to also include plaintext, so it may just be as simple as


if (htmlbody == '' || htmlbody == null){ type = 'plaintext';}


the email message handling will expose plain text and html properties, so all you need to bring is your own comparision logic to determine each.


Since HTML emails should also include a plain text version, I'd recommend having your logic look for the HTML version, rather than the plain text.


Check teh documentation for how to access plaintextbody and htmlbody.