0
votes

The following function uses IConverterSession to create a new message from a mhtm file on disk. With Outlook version < 2016 the result is a html formatted message including css styles and embedded pictures. With Outlook 2016, the original MIME code of the file is added to the mail as text body...

HRESULT ImportEMLToIMessage
(
    LPCWSTR         lpszEMLFile, 
    LPMESSAGE       lpMsg, 
    ULONG           ulConvertFlags
)
{
    HRESULT rv= S_OK;
    if (lpszEMLFile&&lpMsg) {
      // try to create an instance of the converter 
      // interface (CoCreateInstance / DllGetClassObject)
      LPCONVERTERSESSION lpConverter = CreateConverterSession();
      if (lpConverter) {
        // open input stream
        LPSTREAM lpEMLStm = NULL;
        rv= MyOpenStreamOnFile(fctAllocateBuffer, fctFreeBuffer, 
                        STGM_READ, lpszEMLFile, NULL, &lpEMLStm);
        if (lpEMLStm&&SUCCEEDED(rv)) {
          rv= lpConverter->SetEncoding(IET_QP);
          if (SUCCEEDED(rv)) {
            rv= lpConverter->SetSaveFormat(SAVE_RFC1521);
          }
          if (SUCCEEDED(rv)) {
            rv= lpConverter->MIMEToMAPI(lpEMLStm, lpMsg, NULL, ulConvertFlags);
            if (SUCCEEDED(rv)) {
              rv= lpMsg->SaveChanges(NULL);
            }
          }
          lpEMLStm->Release();
        }
      }
      lpConverter->Release();
    }
  }
  return rv;
}

Does anyone know, how to make this work in Outlook 2016? Thanks.

1

1 Answers

0
votes

A few things:
1. Why do you call SetEncoding?
2. Why do you need SetSaveFormat if you are importing a MIME file?
3. What is the value of ulConvertFlags? You never initialize that variable.

Do you see the problem in OutlookSpy (click IConverterSession | MIMEToMAPI)?

You might also want to set the PR_MESSAGE_CLASS property to "IPM.Note" first.