Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Converting Mime to Mapi using iConverterSession

405 views
Skip to first unread message

Dmitry Streblechenko

unread,
Mar 28, 2007, 1:18:56 PM3/28/07
to
IConverterSession is Extended MAPI, which is not supported in C#.
<plug>
Redemption (url below) will do the conversion eaily. In VB:

set Session = CreateObject("Redemption.RDOSession")
set Msg = Session.GetMessageFromMsgFile("c:\newmsgFile.msg", true)
Msg.Import("c:\YourEmlFile.EML", 1024)
Msg.Save

</plug>

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"Esther" <Est...@discussions.microsoft.com> wrote in message
news:ACC8047D-4CBB-48D3...@microsoft.com...
>I am in a crunch to convert internet mail .eml files to mapi .msg files in
> .net, using c#. I read about iConverterSession in the outlook 2003 api,
> but
> I can't seem to find enough information or any sample code on how to
> proceed.
> Can anyone point me in the right direction in regards to whether I have to
> add any reference in my code, etc. Some sample code would be very
> helpful.
>
> If this is not the best way to go, what's my alternative?
>
> Thanks.
> --
> edw


Dmitry Streblechenko

unread,
Mar 28, 2007, 5:40:21 PM3/28/07
to
No, the official MS position is that Extended MAPI is not supported at all
in the .Net environment, be that C# or VB.Net.
You can still of course use a wrapper like MAPI33 or create your own one in
C++/Delphi/etc.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"Esther" <Est...@discussions.microsoft.com> wrote in message

news:8A8E88B0-1F19-4EE6...@microsoft.com...
> Dimitry, Thanks for your response. Is Extended MAPI not supported in
> .net?
> Could it be used with vb.net instead of c#? We have used redemption in
> another project that is similar to this, but they are looking to not use
> it
> here. Is there another way to approach this? Thanks.
> --
> edw

Daniel

unread,
Apr 4, 2007, 7:44:00 AM4/4/07
to
Hello,

I'm learning how to use the Redemption dll...
My objective is to convert eml to msg, before to go in pure VB, I'm doing
some basic test in VBA (under excel),
I installed the CDO library, and declared this library in my vba environment
(Redemption Outlook Library)

I'm trying to reuse the code sample to are proposing such as:
Private Sub CB_ConvertEML2MSG_Click()
'1. Reference: Microsoft Outlook 11.0 Object Library
'2. Reference: Redemption Outlook Library

Set Session = CreateObject("Redemption.RDOSession")
EMLname = "EML_Origin_1"
MSGname = EMLname
EMLpath = ThisWorkbook.Path & EMLname & ".eml"
MSGpath = ThisWorkbook.Path & MSGname & ".msg"
Set Msg = Session.GetMessageFromMsgFile(MSGpath, True)
a = Msg.Import(EMLpath, 1024)
Msg.Save

End Sub

UNFORTUNATELY when a try to set the Session, the system prompts and tells me
that this object is only readable !!??

I guess it's a basic issue...however I failed finding the root-cause

Could you please help me?

Thanks a lot in advance,
Daniel.

Daniel

unread,
Apr 4, 2007, 9:32:01 AM4/4/07
to
Hello,

I found the problem,

thanks

jab...@mweb.co.za

unread,
May 27, 2007, 3:38:57 AM5/27/07
to
Hi Everyone

There are a large number of posts from developers interested in using
Microsoft Outlook's IConverterSession interface. I happen to be one of
those developers. As far I as see there are no type libraries or C++
headers provided. Any chance someone would be kind enough to post the C
++ header for the IConverterSession interface. There is one floating
around on the Internet but it only supports three functions.

Your help is much appreciated

Jamie

sonaligupta

unread,
Jan 15, 2009, 7:39:29 AM1/15/09
to
I am using IConverterSession interface in c #.
I declared the Interface is this way -

class NativeMethods
{
public enum CLSCTX
{
CLSCTX_INPROC_SERVER = 0x1,
CLSCTX_INPROC_HANDLER = 0x2,
CLSCTX_LOCAL_SERVER = 0x4,
CLSCTX_REMOTE_SERVER = 0x10,
CLSCTX_INPROC = CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
CLSCTX_SERVER = CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER,
CLSCTX_ALL = CLSCTX_SERVER | CLSCTX_INPROC_HANDLER
}


public static Guid CLSID_IConverterSession = new Guid("{4e3a7680-b77a-11d0-9da5-00c04fd65685}");

public static Guid IID_IConverterSession = new Guid("{4b401570-b77b-11d0-9da5-00c04fd65685}");

public enum ENCODINGTYPE
{
IET_BINARY = 0,
IET_BASE64 = 1,
IET_UUENCODE = 2,
IET_QP = 3,
IET_7BIT = 4,
IET_8BIT = 5,
IET_INETCSET = 6,
IET_UNICODE = 7,
IET_RFC1522 = 8,
IET_ENCODED = 9,
IET_CURRENT = 10,
IET_UNKNOWN = 11,
IET_BINHEX40 = 12,
IET_LAST = 13
}

public enum MIMESAVETYPE
{
SAVE_RFC822 = 0,
SAVE_RFC1521 = 1
}

[ComImport]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("4b401570-b77b-11d0-9da5-00c04fd65685")]
public interface IConverterSession
{
[PreserveSig]
int Placeholder0();

[PreserveSig]
int SetEncoding(
[In, MarshalAs(UnmanagedType.I4)] ENCODINGTYPE DispId
);

[PreserveSig]
int Placeholder1();

[PreserveSig]
int MIMEToMAPI(
[In, MarshalAs(UnmanagedType.Interface)]
Stream pstm,
[Out, MarshalAs(UnmanagedType.Interface)]
MailItem pmsg,
object pszSrcSrv,
uint ulFlags
);

[PreserveSig]
int MAPIToMIMEStm(
[In, MarshalAs(UnmanagedType.Interface)]
MailItem pmsg,
[Out, MarshalAs(UnmanagedType.Interface)]
Stream pstm,
uint ulFlags
);

[PreserveSig]
int Placeholder2();

[PreserveSig]
int Placeholder3();

[PreserveSig]
int Placeholder4();

[PreserveSig]
int SetTextWrapping(
bool fWrapText,
uint ulWrapWidth
);

[PreserveSig]
int SetSaveFormat(
[In, MarshalAs(UnmanagedType.I4)]
MIMESAVETYPE mstSaveFormat
);

[PreserveSig]
int Placeholder5();

[PreserveSig]
int Placeholder6();
}
}

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 -

Type converter = Type.GetTypeFromCLSID(NativeMethods.CLSID_IConverterSession);
object obj = Activator.CreateInstance(converter);
NativeMethods.IConverterSession session = (NativeMethods.IConverterSession)obj;
int hr = session.SetEncoding(NativeMethods.ENCODINGTYPE.IET_QP);
hr = session.SetSaveFormat(NativeMethods.MIMESAVETYPE.SAVE_RFC822);

if (session != null)
{
Application olApp = new Application();
NameSpace nSpace = olApp.GetNamespace("MAPI");
MailItem msg = (MailItem)olApp.CreateItem(OlItemType.olMailItem);
FileStream stm = File.OpenRead("C:\\e.eml");
hr = session.MIMEToMAPI(stm, msg, null, 0);
msg.Save();
}

I also tried using CoCreateInstance() instead of Activator.CreateInstance() but that also doesn't helped.

Any input on this will be appreciated.

Thanks.

EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com/default.aspx?ref=ng

Dmitry Streblechenko

unread,
Jan 15, 2009, 11:45:18 AM1/15/09
to
See my reply in the mesaging newsgroup.
Please do not multipost.

--

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

-
<Sonali Gupta> wrote in message news:200911573929...@gmail.com...

fidq

unread,
Nov 3, 2010, 11:07:56 AM11/3/10
to
Sonali Gupta wrote on 01/15/2009 07:39 ET :
> I am using IConverterSession interface in c #.
> I declared the Interface is this way -
>
> class NativeMethods
> {
> public enum CLSCTX
> {
> CLSCTX_INPROC_SERVER = 0x1,
> CLSCTX_INPROC_HANDLER = 0x2,
> CLSCTX_LOCAL_SERVER = 0x4,
> CLSCTX_REMOTE_SERVER = 0x10,
> CLSCTX_INPROC = CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
> CLSCTX_SERVER = CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER |
> CLSCTX_REMOTE_SERVER,
> CLSCTX_ALL = CLSCTX_SERVER | CLSCTX_INPROC_HANDLER
> }
>
>
> public static Guid CLSID_IConverterSession = new
> Guid(&quot;{4e3a7680-b77a-11d0-9da5-00c04fd65685}&quot;);

>
> public static Guid IID_IConverterSession = new
> Guid(&quot;{4b401570-b77b-11d0-9da5-00c04fd65685}&quot;);

>
> public enum ENCODINGTYPE
> {
> IET_BINARY = 0,
> IET_BASE64 = 1,
> IET_UUENCODE = 2,
> IET_QP = 3,
> IET_7BIT = 4,
> IET_8BIT = 5,
> IET_INETCSET = 6,
> IET_UNICODE = 7,
> IET_RFC1522 = 8,
> IET_ENCODED = 9,
> IET_CURRENT = 10,
> IET_UNKNOWN = 11,
> IET_BINHEX40 = 12,
> IET_LAST = 13
> }
>
> public enum MIMESAVETYPE
> {
> SAVE_RFC822 = 0,
> SAVE_RFC1521 = 1
> }
>
> [ComImport]
> [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
> [Guid(&quot;4b401570-b77b-11d0-9da5-00c04fd65685&quot;)]
> following exception - &quot;Attempted to read or write protected memory. This
> is often an indication that other memory is corrupt.&quot;

>
> Here is the code I am using -
>
> Type converter =
Type.GetTypeFromCLSID(NativeMethods.CLSID_IConverterSession);
> object obj = Activator.CreateInstance(converter);
> NativeMethods.IConverterSession session =
(NativeMethods.IConverterSession)obj;
> int hr = session.SetEncoding(NativeMethods.ENCODINGTYPE.IET_QP);
> hr = session.SetSaveFormat(NativeMethods.MIMESAVETYPE.SAVE_RFC822);
>
> if (session != null)
> {
> Application olApp = new Application();
> NameSpace nSpace = olApp.GetNamespace(&quot;MAPI&quot;);
> MailItem msg = (MailItem)olApp.CreateItem(OlItemType.olMailItem);
> FileStream stm = File.OpenRead(&quot;C:e.eml&quot;);

> hr = session.MIMEToMAPI(stm, msg, null, 0);
> msg.Save();
> }
>
> I also tried using CoCreateInstance() instead of Activator.CreateInstance()
but
> that also doesn't helped.
>
> Any input on this will be appreciated.
>
> Thanks.
>
> EggHeadCafe - .NET Developer Portal of Choice
> http://www.eggheadcafe.com/default.aspx?ref=ng
>
so what was the solution to fix your problem?
0 new messages