Share via


IConverterSession - Do You Converter Session?

[This is now documented here: https://msdn2.microsoft.com/en-us/library/bb821176.aspx]

Ryan, one of our PMs over in Outlook, got an e-mail to his blog asking for a header for IConverterSession. He knows I'm the MAPI guy so he asked me if I could help out.

Here's the header I use in MFCMAPI - it's built directly from the docs:

 #pragma once
//Class Identifiers
// {4e3a7680-b77a-11d0-9da5-00c04fd65685} 
DEFINE_GUID(CLSID_IConverterSession, 0x4e3a7680, 0xb77a,
 0x11d0, 0x9d, 0xa5, 0x0, 0xc0, 0x4f, 0xd6, 0x56, 0x85); 

//Interface Identifiers
// {4b401570-b77b-11d0-9da5-00c04fd65685} 
DEFINE_GUID(IID_IConverterSession, 0x4b401570, 0xb77b,
 0x11d0, 0x9d, 0xa5, 0x0, 0xc0, 0x4f, 0xd6, 0x56, 0x85);

// These are out of mimeole.h, which is a pain to include
typedef
enum tagMIMESAVETYPE
    {    SAVE_RFC822 = 0,
    SAVE_RFC1521    = SAVE_RFC822 + 1
    }  MIMESAVETYPE;

typedef 
enum tagENCODINGTYPE
    {  IET_BINARY  = 0,
    IET_BASE64  = IET_BINARY + 1,
   IET_UUENCODE    = IET_BASE64 + 1,
   IET_QP  = IET_UUENCODE + 1,
 IET_7BIT    = IET_QP + 1,
   IET_8BIT    = IET_7BIT + 1,
 IET_INETCSET    = IET_8BIT + 1,
 IET_UNICODE = IET_INETCSET + 1,
 IET_RFC1522 = IET_UNICODE + 1,
  IET_ENCODED = IET_RFC1522 + 1,
  IET_CURRENT = IET_ENCODED + 1,
  IET_UNKNOWN = IET_CURRENT + 1,
  IET_BINHEX40    = IET_UNKNOWN + 1,
  IET_LAST    = IET_BINHEX40 + 1
    }     ENCODINGTYPE;

// Constants
#define CCSF_SMTP      0x0002
#define CCSF_NOHEADERS        0x0004
#define CCSF_INCLUDE_BCC  0x0020
#define CCSF_USE_RTF      0x0080
#define CCSF_NO_MSGID     0x4000

interface IConverterSession : public IUnknown
{
    public:
 virtual HRESULT PlaceHolder1();
 virtual HRESULT STDMETHODCALLTYPE SetEncoding(ENCODINGTYPE et);
 virtual HRESULT PlaceHolder2();
 virtual HRESULT STDMETHODCALLTYPE MIMEToMAPI(LPSTREAM pstm,
         LPMESSAGE pmsg,
         LPCSTR pszSrcSrv,
           ULONG ulFlags);
 virtual HRESULT STDMETHODCALLTYPE MAPIToMIMEStm(LPMESSAGE pmsg,
         LPSTREAM pstm,
          ULONG ulFlags);
 virtual HRESULT PlaceHolder3();
 virtual HRESULT PlaceHolder4();
 virtual HRESULT PlaceHolder5();
 virtual HRESULT STDMETHODCALLTYPE SetTextWrapping(BOOL fWrapText,
           ULONG ulWrapWidth);
 virtual HRESULT STDMETHODCALLTYPE SetSaveFormat(MIMESAVETYPE mstSaveFormat);
    virtual HRESULT PlaceHolder8();
 virtual HRESULT PlaceHolder9();
};

Lemme know if I left anything out or made any mistakes and I'll fix them up. Enjoy!

†Pardon the bad pun in the title. Couldn't resist.

Comments

  • Anonymous
    June 22, 2007
    Hi there Thank you for getting back to me. I was in fact the developer who asked for this information, but I figured out on my own.  The header you posted is in fact in the MSDN library, but it is missing some crucial methods. For example, if you used the header as stated it would not produced RFC822 compliant messages as the email address fields would not be expanded correctly. This is the header that, with the help of others, I have constructed: [sgriffin here - I've excised this bit because it includes functions that we have not documented and I don't want my blog to be used for reverse engineering.]

  • Anonymous
    June 22, 2007
    Missing pieces? Sure! :-)

  1. PlaceHolder1 - still undocumented. And it is a pretty important piece.
  2. CCSF_USE_RTF - won't work unless another bit (0x10) is also set. What is it? I am sure Lev can think of at least a dozen more missing pieces...
  • Anonymous
    June 22, 2007
    I'm checking with dev to see if there's any more of this API that we can document. That said - when I asked if I missed anything I meant did I leave out anything that has been documented. :)

  • Anonymous
    June 29, 2007
    Thank you for looking into this. We are left wondering whether Microsoft is deliberately trying to prevent people from converting MAPI messages to standard formats? This functionality should have been available long time ago! It would be nice if the MAPI engineering team would allow the rest of the world to interoperate with their proprietary system.

  • Anonymous
    July 07, 2007
    Is there some progress in this question? I think a lot of developer needs this informations. Will Microsoft document the missing functions of that interface?

  • Anonymous
    July 20, 2007
    Good news, everyone! We've decided to document some more flags and functions for IConverterSession .

  • Anonymous
    May 27, 2008
    Hi Guys! IConverterSession would save my skin. But having the header file woulb pass the compile but not the linker. Wouldn`t I need a lib and dll as well? Thanks

  • Anonymous
    May 27, 2008
    The comment has been removed

  • Anonymous
    June 17, 2008
    The comment has been removed

  • Anonymous
    June 17, 2008
    IConverterSession is not an OS provided API. It's provided by Outlook. What versions of Outlook do you have installed on these two machines?

  • Anonymous
    June 17, 2008
    The machine where it works has Outlook 2003. The machine where does not work is a virtual machine, so we don't have Outlook installed on it. Due to this, we copied and registered the same version of OUTLMIME.DLL that we have in the machine that it is working.  Is it possible that some other registration or even some other DLL is missing ?

  • Anonymous
    June 17, 2008
    I don't see why a machine being virtual would mean you wouldn't have Outlook installed on it, but regardless, that's the problem. Outlook has to be installed to use this API. You can't go copying random DLLs and expect things to work.

  • Anonymous
    June 18, 2008
    OK. So, there is no other way to use this API than installing (and not necessarily running) Outlook on this machine. Just for curiosity, how complex would be to implement the IConverterSession manually?

  • Anonymous
    June 18, 2008
    It's not a trivial API to implement. And you'd still need some version of MAPI installed on the machine.

  • Anonymous
    August 25, 2008
    IConverterSession needs that Outlook (Office and Express) must be installed on the computer. If i install <Microsoft Exchange Server MAPI Client and Collaboration Data Objects 1.2.1> instead of Outlook, can i use IConverterSession to convert MSG to EML format (is this enough) ? What can you advice me to read MSG file format from C# ! I found this <http://www.codeproject.com/KB/cs/MsgReader.aspx> but from a MSG file, it only reads the plain text body and not the HTML body ! Thank you

  • Anonymous
    August 25, 2008
    The comment has been removed

  • Anonymous
    August 26, 2008
    When using OutlookSpy, i took a mail message and i see that the HTML body part is the property PR_HTML WHEN i inspect only the mail message within Outlook from my folder "Receinving". When i saved the same mail message as MSG file format from the SaveAs Outlook menu. When i read it with OutlookSpy as an external file, the PR_HTML MAPI property is not used. To read the body part from this loaded mail message, i must use the PR_RTF_COMPRESSED MAPI property. But I do not known what to do with RTF. I need a HTML body part. Is there a setting in outlook in order to save a mail message in the PR_HTML MAPI property as HTML content ? By usin Outlook API, can i retrieve the HMTL body part from a MSG message. How to proceed by usin C# ? Thank you very much.

  • Anonymous
    November 11, 2008
    Hello, might I ask how IConverterSession::SetEncoding works? Actually, is there a way to enforce Exchange MAPI to set the encoding to some specific value (ie. quoted-printable) or does it always just do it on its own? The closest MAPI property I could find was PR_SEND_INTERNET_ENCODING but it doesn't seem to allow me to specify the actual encoding type. Since this interface allows Outlook to do it, I'm guessing I should be able to also do it directly using a MAPI property? Thanks in advance.

  • Anonymous
    November 11, 2008
    SetEncoding just sets an internal variable used later during the conversion. It's not setting anything on the message.

  • Anonymous
    November 11, 2008
    Is there anything in the message that I could set so that I could enforce something like quoted-printable or base64 in the content-transfer-encoding? Are there other bits in PR_SEND_INTERNET_ENCODING that aren't documented?

  • Anonymous
    December 24, 2008
    I am using MAPIToMIMEStm function for creating an .eml file. It seems that the above function excludes some properties like PR_ICON_INDEX, which is used for showing colors assigned to notes and calendar items on the icon/envelope. Therefore when the file is again imported to outlook using MIMEToMAPI colors assigned to Notes are not visible on the envelope/icon though they are visible when the Notes is opened. The flags passed to MAPIToMIMEStm are CCSF_SMTP | CCSF_USE_TNEF | CCSF_USE_RTF. I have tried saving the file in RFC 822 and 1521 format but none them solve the problem. Is this a bug with IConvertorSession implementation? How can I add the above mentioned property to the .eml file?

  • Anonymous
    January 15, 2009
    I am using IConverterSession interface in c #. I declared the Interface is this way - <lengthy code block excised> I created an Instance of IConverterSession.I tried calling methods SetEncoding(), SetSaveFormat() on that instance, these methods are executed successfully. But when I call MIMEToMAPI() on the same instance it gives following exception - "Attempted to read or write protected memory. This is often an indication that other memory is corrupt." Here is the code I am using - <lengthy code block excised> I also tried using CoCreateInstance() instead of Activator.CreateInstance() but that also doesn't helped. Any input on this will a great help. Thanks.

  • Anonymous
    January 16, 2009
    Sonali - MAPI's not supported with .Net. Since this interface requires MAPI, it wouldn't be supported with .Net either.

  • Anonymous
    August 05, 2009
    MAPIToMIMEStm returns E_INVALIDARG for some messages, it works only if CCSF_NOHEADERS is passed along with CCSF_SMTP. I have tried all many different combinations of convector flags, also tried different encoding, storage format i.e. RFC  etc. Nothing works unless CCSF_NOHEADERS is passed. What could be the problem here. Tried the conversion with MFCMAPI and Outlook Spy.

  • Anonymous
    August 11, 2009
    If an email has To and Cc list empty, this can happen if mail is sent with users in Bcc only. On converting the mail to EML file the Sender is set in the To list. Is this a bug or an expected behavior.

  • Anonymous
    January 14, 2010
    Is there a bug in the Outlook 2007 MimetoMAPI function?  Granted it's an interop situation (Exchange to our MAPI provider), but the exact same thing works in Outlook 2003 and Outlook 2010: Our user sends update of recurrence to Exchange user, changing the date an of occurrence.  Exchange user accepts.  MimeToMAPI can't parse acceptance message -- returns MAPI_W_PARTIAL_COMPLETION.  It works fine if we just change the time of the occurrence, but changing the date causes this problem only in Outlook 2007. These acceptance messages are multipart/alternative messages with the calendar part base64 encoded.  I base 64 decoded these, and they look fine.  The only appreciable differences between the good one (just changed time) and the bad one (changed date) are the X-MICROSOFT-CDO-APPT-SEQUENCE, SEQUENCE, and obviously the start times and RECURRENCE-IDs.  Syntactically, they're all fine. This seems to point to a bug here.  Had you heard of such a bug? I use Outlook 2007 (12.0.6514.5000) SP2 MSO (12.0.6425.1000) Thanks

  • Anonymous
    February 27, 2010
    Hi,  I am facing couple problems with IConverterSession:  1) IConverterSession is not able to convert bounced messages? I am getting E_INVALID return code ? Is this expected ?  2) I see that the mailing list names are not resolved during translation ? I did SetAdrBook but still not working ? Any clues ?

  • Anonymous
    April 07, 2010
    The comment has been removed

  • Anonymous
    January 12, 2011
    Hi, I am using IConverterSession::MapiToMimeStm() with installed Outlook 2010 and Outlook 2007 - OUTLMIME.DLL crashes with an Access violation on some (not all) Outlook profiles. The callstack shows mlang.dll involved, but I don't get any symbols. Most of the time everything is working fine with the same calls (so I don't think my parameters are wrong). It's only happening on some PST files and Outlook profiles. Can you give me a hint regarding that issue? Is there a known issue in some situations / configurations? Thanks.

  • Anonymous
    October 30, 2013
    The comment has been removed

  • Anonymous
    October 30, 2013
    This is a known issue with the C2R version of Outlook. We're still working on how to approach fixing it. Just registering the classes is problematic because we now support C2R on the same machine as MSI installs of Outlook 2010, which depends on the classes it registered.

  • Anonymous
    October 31, 2013
    Thanks Stephen! Is there any other way to do MAPIToMIME that is supported on Outlook 2013 C2R?

  • Anonymous
    October 31, 2013
    If you can figure out how to load those interfaces without relying on the registry that would work.

  • Anonymous
    October 31, 2013
    The comment has been removed

  • Anonymous
    October 31, 2013
    If you think this might be a different issue I'd advise opening a case to have it investigated.

  • Anonymous
    January 06, 2014
    The comment has been removed

  • Anonymous
    September 03, 2014
    Hi, Stephen! Looking at the IConverterSession::SetEncoding documentation (and also answered in one of the comments above), I found that it only applies to "the outermost message body of a mail item" and that "Outlook chooses the encoding for any individual attachments". For a very specific application I need to have all attachments always encoded as base64 (I'm not concerned about the size of the resulting messages at all, just prefer base64 over any other Content-Transfer-Encoding in this particular case). Is there a way to tell the IConverterSession to use base64 encoding for all attachments, and not to use its internal statistical/magic encoding chooser when exporting messages with the MAPIToMIMEStm method? I'll really appreciate any help. Thanks!