Converting Mime to Mapi using iConverterSession

E

Esther

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.
 
D

Dmitry Streblechenko

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
 
E

Esther

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.
 
D

Dmitry Streblechenko

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
 
D

Daniel

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.
 
D

Daniel

Hello,

I found the problem,

thanks

Daniel said:
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.
 
J

jaband

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
 
D

Dmitry Streblechenko

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top