none
How to set message encoding in EWS? RRS feed

  • Question

  • I want set encoding for my HTML messages. I insert in "HTML" body this tag:

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

    But when I save my message value of "charset" changes to "koi8-r". 

    I found property PidTagInternetCodepage (PR_INTERNET_CPID - 0x3FDE) which should help me. But when I save message with "HTML" body, value of "charset" same changes to "koi8-r" and text becomes unreadable. Although in Outlook (and MIME) I can see that the encoding has changed to the desired.

    Maybe there is another way to change the character set (without set MimeContent) or am I doing something wrong?

    Thursday, June 1, 2017 4:27 PM

All replies

  • What's the encoding of the SOAP message your sending ? eg first line

    <?xml version="1.0" encoding="utf-8"?>

    Cheers
    Glen

    Friday, June 2, 2017 6:12 AM
  • I use EWS Managed API. It creates the following query:

    Content-Type: text/xml; charset=utf-8
    Accept: text/xml
    Accept-Encoding: gzip,deflate
    
    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <soap:Header>
        <t:RequestServerVersion Version="Exchange2010_SP1" />
      </soap:Header>
      <soap:Body>
        <m:CreateItem MessageDisposition="SaveOnly">
          <m:SavedItemFolderId>
            <t:DistinguishedFolderId Id="drafts" />
          </m:SavedItemFolderId>
          <m:Items>
            <t:Message>
              <t:ItemClass>IPM.Note</t:ItemClass>
              <t:Subject>Проблема</t:Subject>
              <t:Body BodyType="HTML">&lt;html&gt;&lt;head&gt;
    &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;
    &lt;/head&gt;&lt;body&gt;Текст&lt;/body&gt;&lt;/html&gt;&lt;/body&gt;&lt;/html&gt;</t:Body>          
              <t:ToRecipients>
                <t:Mailbox>
                  <t:Name></t:Name>
                  <t:EmailAddress>test@test.com</t:EmailAddress>
                </t:Mailbox>
              </t:ToRecipients>
            </t:Message>
          </m:Items>
        </m:CreateItem>
      </soap:Body>
    </soap:Envelope>

    As a result, message with encoding "koi8-r". MIME: 

    To: "test@test.com" <test@test.com>
    Subject: =?koi8-r?B?8NLPwszFzcE=?=
    Thread-Topic: =?koi8-r?B?8NLPwszFzcE=?=
    Thread-Index: AQHS32dJ/Bj1YgtQYUCmNGUxGDw7+g==
    Content-Language: en-US
    X-MS-Has-Attach:
    X-MS-TNEF-Correlator:
    Content-Type: multipart/alternative;
    	boundary="_000_HE1PR07MB3115A8C0B8082DE683BE658EFCC80HE1PR07MB3115eurp_"
    MIME-Version: 1.0
    
    --_000_HE1PR07MB3115A8C0B8082DE683BE658EFCC80HE1PR07MB3115eurp_
    Content-Type: text/plain; charset="koi8-r"
    Content-Transfer-Encoding: quoted-printable
    
    =F4=C5=CB=D3=D4
    
    --_000_HE1PR07MB3115A8C0B8082DE683BE658EFCC80HE1PR07MB3115eurp_
    Content-Type: text/html; charset="koi8-r"
    Content-Transfer-Encoding: quoted-printable
    
    <html>
    <head>
    <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dkoi8-r">
    </head>
    <body>
    =F4=C5=CB=D3=D4
    </body>
    </html>
    
    --_000_HE1PR07MB3115A8C0B8082DE683BE658EFCC80HE1PR07MB3115eurp_--
    • Edited by vangog163 Wednesday, June 7, 2017 8:43 AM Formatting
    Wednesday, June 7, 2017 8:39 AM
  • Mime generation should be done on the fly by the store have you tried posting the MIME content directly to see if that changes it https://msdn.microsoft.com/en-us/library/office/hh545614%28v=exchg.140%29.aspx

    Cheers
    Glen

    Thursday, June 8, 2017 4:54 AM
  • Thank you, Glen.
    Outlolok for Mac (use EWS API) posting the MIME content directly and in this case the desired encoding does not change
    But I would like MIME was generated on the store side. For this reason, I experimented with the property PidTagInternetCodepage (PR_INTERNET_CPID - 0x3FDE).
    Maybe there is a way without posting the MIME content directly?
    Thursday, June 8, 2017 8:40 AM