Character encoding problem RRS feed

  • Question

  • Hello,

    We're facing a character encoding problem with a backend application that we developed and that send emails.

    When the emails have accented characters, they are displayed this way in outlook :  (fyi : they are well displayed in gmail).

    After some tests, I think I found why.

    Our backend application is using  the JavaMail API to send the emails. We are using the SMTPMessage class and more precisely the setContent method to set the body of the mail and its mime type. Here is the JavaDoc of this method :


    public void setContent(Object o,
                           String type)
                    throws MessagingException
    A convenience method for setting this Message's content.

    The content is wrapped in a DataHandler object. Note that a DataContentHandler class for the specified type should be available to the JavaMail implementation for this to work right. i.e., to do setContent(foobar, "application/x-foobar"), a DataContentHandler for "application/x-foobar" should be installed. Refer to the Java Activation Framework for more information.

    o - the content object
    type - Mime type of the object

    So, here is the code we use to set the body of the email :

    message.setContent(body, "text/html");

    After some tests, I found out that if I modify this line of code like this :

    message.setContent(body, "text/html; charset=UTF-8");

    the accented characters are well displayed in Outlook.

    What I don't understand is why do I have to set the charset for the accented charaters to be well displayed while this charset is already setted in the header :

    Content-Type: text/html; charset="UTF-8"
    Content-Transfer-Encoding: quoted-printable

    Moreover, the JavaMail API is only expecting a mime type, and not a charset.

    Thank you for the explanation

    • Moved by Bill_Stewart Thursday, January 25, 2018 10:39 PM Off-topic
    Friday, November 17, 2017 3:23 PM

All replies

  • 1This is  not a Java forum.  You will need to post your issues in the Oracle Java forum for assistance.


    Friday, November 17, 2017 4:26 PM
  • I'm sorry but this is not a Java problem.

    I just want to undestand why Outlook is not interpreting our mails even if the encoding is past in the header.

    It's the third Microsoft forum I'm trying to have an answer and each time, the person who tried to help me send me to another forum.

    Monday, November 20, 2017 7:35 AM
  • That is because no one can understand what you are asking.  You post Java script and ask a question about Outlook.   YOU fail to say what this has to do with scripting.  This is a scripting forum and not an Outlook forum or in a mail API forum.


    • Edited by jrv Monday, November 20, 2017 10:42 AM
    Monday, November 20, 2017 10:40 AM
  • A colleague of yours from the outlook forum told me to ask my question here because the outlook forum was not the good one. So sorry but I'm a bit lost here.
    Monday, November 20, 2017 12:55 PM
  • You would need to use the Outlook developer forum and not the end user forum.  They can tell you how an email needs to be structured for correct display in Outlook or other SMTP client applications.


    Monday, November 20, 2017 1:03 PM
  • I see you have posted in the forum I was going to suggest:


    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    Monday, November 20, 2017 4:51 PM
  • The normal header for Outlook SMTP mail is:

    <meta http-equiv=Content-Type content="text/html; charset=windows-1252">

    "utf-8" is not a character set it is an "encoding".


    Monday, November 20, 2017 5:12 PM