質問

What happens when I choose to block HTML emails in my email client?

  1. Does it strip the HTML contents from my email?
  2. Does it look for alternate text part in the MIME content?

I tried outlook 2010 and It stripped the HTML content and displayed just the text. I am not sure if it because it couldn't find the text content or outlook simply stopped looking for text content and strips the HTML.

Below is snippet of my code,

//HTML Version
BodyPart htmlBodyPart = new MimeBodyPart();
htmlBodyPart.setContent(htmlContent, "text/html");

//Text Version
BodyPart textBodyPart = new MimeBodyPart();
textBodyPart.setContent(textContent, "text/plain");

Multipart multipart = new MimeMultipart("alternative");
multipart.addBodyPart(textBodyPart); //add text part
multipart.addBodyPart(htmlBodyPart); //add html part

And surprisingly Google didn't help me on this one.

役に立ちましたか?

解決

It seems that Outlook does not use the text/plain alternative, and when configured to display messages as plain text, it uses the text/html part, converted to plain text.

I found a confirmation of that behavior on the following links:

Other (most?) email clients, Thunderbird for example, will display the text/plain alternative when configured to show messages as text. But what Outlook does (using the text/html part) does not seem to be a bug - from Wikipedia MIME:

Systems can then choose the "best" representation they are capable of processing; in general, this will be the last part that the system can understand, although other factors may affect this.

Apparently, it's also recommended to have similar content in both HTML and TEXT versions to avoid being classified as spam - from the same Wikipedia page:

Anti-spam software eventually caught up on this trick, penalizing messages with very different text in a multipart/alternative message.

So, I would recommend to build the text/plain part with the content of the text/html part converted to text, so that

  • all email clients configured to display emails as text display the email content the same way
  • probability to be classified as spam is not increased because of parts with different content

他のヒント

Most modern browsers will use the text/plain alternative to show your email without HTML (so they will switch to the plain text version of the email. If that is not available, they will strip the HTML and just show the text. Or, in other words, parse the html and not use it. Besides that, I'm pretty sure you will be able to find some mailclients that are not capable of stripping the html, and will just show you the raw html code.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top