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

EML to MSG Conversion

8 views
Skip to first unread message

justju...@gmail.com

unread,
Apr 4, 2008, 7:43:15 AM4/4/08
to
Hi there,
I need to convert EML to MSG format preserving everything. Is this
possible?
But i am having a problem.
Please help me on this:
My code goes like this:

LPMESSAGE* outMessage=new LPMESSAGE();// NULL;
LPSTREAM pMimeStream = NULL;
IConverterSession *pConverterSession = NULL;
DWORD dwFileSize = 0;
HANDLE hFile = NULL;
LPVOID pvData = NULL;
HGLOBAL hGlobal = NULL;
DWORD dwBytesRead = 0;
BOOL bRead = FALSE;
// open file
hFile = CreateFile((LPCSTR)inMimeFile, GENERIC_READ,1, NULL,
OPEN_EXISTING, 0,NULL);
dwFileSize = GetFileSize(hFile, NULL);
// alloc memory based on file size
hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize);
pvData = GlobalLock(hGlobal);
// read file and store in global memory
bRead = ReadFile(hFile, pvData, dwFileSize, &dwBytesRead, NULL);
GlobalUnlock(hGlobal);
CloseHandle(hFile);
hr = CreateStreamOnHGlobal(hGlobal, TRUE, &pMimeStream);
if(hr==S_OK)
{
hr=CoCreateInstance(CLSID_IConverterSession,NULL,CLSCTX_INPROC_SERVER,IID_IConverterSession,
(void **)&pConverterSession);
if(hr==S_OK)
{
hr=pConverterSession->SetEncoding(IET_BASE64);
if(hr==S_OK)
{
hr=pConverterSession-
>MIMEToMAPI(pMimeStream,*outMessage,NULL,CCSF_SMTP | CCSF_INCLUDE_BCC|
CCSF_NO_MSGID);
if(hr==S_OK)
{
ipmMessage->Mes=*outMessage;
}
}
}
}
return hr;

When i call MIMETo MAPI method i am getting error code -2147287015.
I suppose this is STG_E_SEEKERROR.
What is wrong here?


My other variables are:

DEFINE_GUID(CLSID_IConverterSession, 0x4e3a7680, 0xb77a, 0x11d0, 0x9d,
0xa5,
0x0, 0xc0, 0x4f, 0xd6, 0x56, 0x85);
DEFINE_GUID(IID_IConverterSession, 0x4b401570, 0xb77b, 0x11d0, 0x9d,
0xa5,
0x0, 0xc0, 0x4f, 0xd6, 0x56, 0x85);

typedef enum tagENCODINGTYPE {
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
} ENCODINGTYPE;

typedef enum tagMIMESAVETYPE {
SAVE_RFC822 = 0,
SAVE_RFC1521 = 1
} MIMESAVETYPE;


typedef enum tagCCSF {
CCSF_SMTP = 0x0002,
CCSF_NOHEADERS = 0x0004,
CCSF_NO_MSGID = 0x4000,
CCSF_USE_RTF = 0x0080,
CCSF_INCLUDE_BCC = 0x0020
} CCSF;

/*!Inteface defining the methods that are used to convert mime to
mapi*/
interface DECLSPEC_UUID("4B401570-B77B-11D0-9DA5-00C04FD65685")
IConverterSession : public IUnknown
{
private:
STDMETHOD(placeholder0)() PURE;
public:
STDMETHOD(SetAddressBook) ( LPADRBOOK pAddrBook ) PURE;
STDMETHOD(SetEncoding)(ENCODINGTYPE et) PURE;
private:
STDMETHOD(placeholder1)() PURE;
public:
STDMETHOD(MIMEToMAPI)(LPSTREAM pstm,LPMESSAGE pmsg,LPCSTR
pszSrcSrv,ULONG ulFlags) PURE;
STDMETHOD(MAPIToMIMEStm)(LPMESSAGE pmsg,LPSTREAM pstm,ULONG ulFlags)
PURE;
private:
STDMETHOD(placeholder2)() PURE;
STDMETHOD(placeholder3)() PURE;
STDMETHOD(placeholder4)() PURE;
public:
STDMETHOD(SetTextWrapping(BOOL fWrapText,ULONG ulWrapWidth)) PURE;
STDMETHOD(SetSaveFormat(MIMESAVETYPE mstSaveFormat)) PURE;
private:
STDMETHOD(placeholder5)() PURE;
STDMETHOD(placeholder6)() PURE;
};

help me
miztaken

Dmitry Streblechenko

unread,
Apr 5, 2008, 12:19:37 PM4/5/08
to
Doyou have a valid IMessage? I do not see it being initiwlized anywhere.
See http://support.microsoft.com/kb/171907

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
<justju...@gmail.com> wrote in message
news:0b318fcc-4ce4-4717...@s37g2000prg.googlegroups.com...

justju...@gmail.com

unread,
Apr 6, 2008, 2:40:03 AM4/6/08
to
Hi dmitry,
I initilized the msg file but still its showing the same error.
I did it like this:-

LPWSTR lpWideCharStr = NULL;
ULONG cbStrSize = 0L;
LPSTORAGE pStorage = NULL;
LPMSGSESS pMsgSession = NULL;
LPMALLOC pMalloc=MAPIGetDefaultMalloc();
cbStrSize=MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,outMsgFile,-1,lpWideCharStr,
0);
MAPIAllocateBuffer(cbStrSize * sizeof(WCHAR),(LPVOID
*)&lpWideCharStr);
MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,outMsgFile,-1,lpWideCharStr,cbStrSize);
hr=StgCreateDocfile(lpWideCharStr,STGM_CREATE|STGM_READWRITE|
STGM_TRANSACTED,0,&pStorage);
hr=OpenIMsgSession(pMalloc,0,&pMsgSession);
hr=OpenIMsgOnIStg(pMsgSession,MAPIAllocateBuffer,MAPIAllocateMore,MAPIFreeBuffer,pMalloc,NULL,pStorage,NULL,
0,0,&outMessage);
hr=WriteClassStg(pStorage,CLSID_MailMessage);
Till here hr returns 0 i.e S_OK
but after that when i execute:

hr=pConverterSession-
>MIMEToMAPI(pMimeStream,outMessage,NULL,CCSF_SMTP);// |
CCSF_INCLUDE_BCC|CCSF_NO_MSGID);

Then it returns the same error:
2147287015 (STG_E_SEEKERROR)

Help me

justju...@gmail.com

unread,
Apr 6, 2008, 3:50:03 AM4/6/08
to
Hi dimtry,

Its working now. It stated working.
But when i tried to open the saved MSG file then it says "Cannot start
microsoft office outlook. Unable to read the item."
The size of MSG file is always 5 KB.

From beginning to end.. all hr returned S_OK but i am unable to get
the result.

What is wrong.
help me
miztaken

Dmitry Streblechenko

unread,
Apr 6, 2008, 11:11:18 PM4/6/08
to
Do you save the message?
Do you set the PR_MESSAGE_CLASS property?
What do you see in OutlookSpy if you click Misc | OpenIMsgOnIStg?

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
<justju...@gmail.com> wrote in message
news:5503a34d-c8a0-46c6...@p39g2000prm.googlegroups.com...

justju...@gmail.com

unread,
Apr 7, 2008, 7:52:51 AM4/7/08
to
Hi Dmitry,
I have properly saved the message.
I now set, PR_MESSAGE_TYPE to IPM.Note and it opened in outlook but to
my surprise the MSG file was blank.
What am i missing ?
I have done like this:-
hr=pConverterSession->MIMEToMAPI(pMimeStream,outMessage,NULL,0x0002);//
CCSF_SMTP|CCSF_INCLUDE_BCC|CCSF_NO_MSGID);
SPropValue sp[1];
sp[0].ulPropTag=PR_MESSAGE_CLASS;
sp[0].dwAlignPad=0;
sp[0].Value.lpszA="IPM.Note";
hr=outMessage->SetProps(1,sp,NULL);
hr=outMessage->SaveChanges(KEEP_OPEN_READWRITE);
pConverterSession->Release();
hr = pStorage->Commit(STGC_DEFAULT);
MAPIFreeBuffer ( lpWideCharStr );
pStorage->Release();
outMessage->Release();
CloseIMsgSession(pMsgSession);

BTW outlook spy saves it correctly.


I dont have any clue what is wrong here.


Thank You

Dmitry Streblechenko

unread,
Apr 7, 2008, 1:16:23 PM4/7/08
to
And what do you see when you look at the IMessage properties in OutlookSpy?

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
<justju...@gmail.com> wrote in message

news:3eb8c2be-0157-4b42...@q27g2000prf.googlegroups.com...

justju...@gmail.com

unread,
Apr 8, 2008, 1:16:11 AM4/8/08
to

Hi Dmitry,
When i checked the saved IMessage with outlook spy, it shows nothing.
Nothing is set.
Is there any particular FLAG i should for?

And BTW is the method MIMETOMAPI enough to convert EML files (Outlook
express file) to MSG files (Office Outlook) files or we need some MIME
parser?

Thank You

Dmitry Streblechenko

unread,
Apr 9, 2008, 3:03:46 PM4/9/08
to
But PR_MESSAGE_CLASS was properly set, right?
You never check the result of the MIMEToMAPI() call. Does iot retrun
anything but S_OK?

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
<justju...@gmail.com> wrote in message

news:b414b611-2f1e-4185...@s8g2000prg.googlegroups.com...

josephgo...@gmail.com

unread,
Dec 3, 2018, 1:12:41 AM12/3/18
to
With EML to MSG Converter, import as many numbers of EML files to MSG format along with all the attached data. This tool capable to convert multiple EML files at once to save your time. It supports to import all type of EML files created from any EML application. visit at : http://www.osttopstapp.com/eml-to-msg.html
0 new messages