locked
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 :

    setContent

    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.

    Parameters:
    o - the content object
    type - Mime type of the object
    Throws:
    MessagingException
     

    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

    Thursday, November 16, 2017 1:56 PM

All replies

  • Hi Audrey,

    Thanks for visiting our forum.

    From your description, it seems to me the query is related to using java script to developing the mail application. But here we mainly focus on general issues about Outlook client User interface any my knowledge about code is quite limited. In this situation, it is suggested to post a new thread to the following dedicated scripting forum, that's where most of the scripting experts hang out:  

    https://social.technet.microsoft.com/Forums/scriptcenter/en-us/home?forum=ITCG

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.

    Best regards,
    Yuki Sun


    Please remember to mark the replies as answers if they helped.
    If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Friday, November 17, 2017 8:29 AM
  • Hello,

    Thanks. That's what I'll do.

    Friday, November 17, 2017 3:24 PM
  • Hi Audrey,

    You're welcome :) 

    Best regards,
    Yuki Sun


    Please remember to mark the replies as answers if they helped.
    If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Monday, November 20, 2017 1:27 AM
  • Hello again.

    I'm told by the jrv on the scripting forum that my question has nothing to do with scripting (which is right I think).

    So, again, why Outlook is not interpreting my accentued characters even though the characters encoding is in the header of the mail ?

    Moreover, sometimes the characters are weel displayed (1 on 20 times maybe).

    Thanks

    Monday, November 20, 2017 12:58 PM