|
|
|
date: Mon, 28 Jul 2008 07:32:44 -0700 (PDT),
group: microsoft.public.platformsdk.mapi
back
Re: Working with .msg files that are attachments
#pragma once
//#include <mimeole.h>
#define CCSF_SMTP 0x0002
#define CCSF_NOHEADERS 0x0004
#define CCSF_USE_TNEF 0x0010
#define CCSF_INCLUDE_BCC 0x0020
#define CCSF_8BITHEADERS 0x0040
#define CCSF_USE_RTF 0x0080
#define CCSF_PLAIN_TEXT_ONLY 0x1000
#define CCSF_NO_MSGID 0x4000
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;
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);
interface IConverterSession : IUnknown
{
virtual STDMETHODIMP SetAdrBook(LPADRBOOK pab);
virtual STDMETHODIMP SetEncoding (ENCODINGTYPE et);
virtual STDMETHODIMP IConverterSessionPlaceHolder1();
virtual STDMETHODIMP MIMEToMAPI (LPSTREAM pstm, LPMESSAGE pmsg, LPCSTR pszSrcSrv, ULONG ulFlags );
virtual STDMETHODIMP MAPIToMIMEStm(LPMESSAGE pmsg,LPSTREAM pstm, ULONG ulFlags);
virtual STDMETHODIMP IConverterSessionPlaceHolder2();
virtual STDMETHODIMP IConverterSessionPlaceHolder3();
virtual STDMETHODIMP IConverterSessionPlaceHolder4();
virtual STDMETHODIMP SetTextWrapping (BOOL fWrapText, ULONG ulWrapWidth);
virtual STDMETHODIMP SetSaveFormat (MIMESAVETYPE mstSaveFormat );
virtual STDMETHODIMP IConverterSessionPlaceHolder5();
virtual STDMETHODIMP IConverterSessionPlaceHolder6();
//virtual STDMETHODIMP SetCharset(BOOL fApply, HCHARSET hcharset,CSETAPPLYTYPE csetapplytype);
};
date: Mon, 28 Jul 2008 23:26:53 +0530
author: Ashutosh am
Re: Working with .msg files that are attachments
Use something like [this may not be the best way to. Use it at your own risk]
#define _MSGSESS IMessage
#include <imessage.h>
.
.
.then
CComPtr<IMessage> pMessage;
CComPtr<IStorage> pStorage;
LPMSGSESS pMsgSession = NULL;
LPMSGSESS pIMsg = NULL;
HRESULT hRes;
LPMALLOC pMalloc = MAPIGetDefaultMalloc();
hRes = ::StgOpenStorage(L"c:\\a.msg",NULL, STGM_READWRITE | STGM_TRANSACTED,NULL,NULL,&pStorage);
// Open an IMessage interface on an IStorage object
if(FAILED(hRes) )
return;
//TODO: verify that CLSID is CLSID_MailMessage using ReadClassStg
// Open an IMessage session.
hRes = ::OpenIMsgSession(pMalloc, 0, &pMsgSession);
if(FAILED(hRes) || !pMsgSession)
{
Debug(DebugLevel::Error,_T("Error [%#08x] from OpenIMsgSession - %s"),hRes, CMAPIHealper::GetErrorDetails(hRes));
return ;
}
hRes = ::OpenIMsgOnIStg(pMsgSession, MAPIAllocateBuffer, MAPIAllocateMore, MAPIFreeBuffer, pMalloc, NULL, pStorage, NULL, 0, 0, &pIMsg);
if(FAILED(hRes) || !pIMsg)
{
Debug(DebugLevel::Error,_T("Error [%#08x] from OpenIMsgSession - %s"),hRes, CMAPIHealper::GetErrorDetails(hRes));
pMsgSession->Release();
return ;
}
CMAPIHealper::DumpProperties(pIMsg);
//release other interfaces...
-> at this point you have a valid IMessage interface pIMsg, you can retrieve any properties...
I just ran this code and I could see all the properties correctly. Now that you have an IMessage, you can read its content, its attachment in the usual MAPI way.
Hope you can convert this to C#!
--
Regards,
Ashutosh Bhawasinka
email: discussion@ashutosh.in
MCSA - Messaging,
MCTS - .Net Windows Apps
airwot4 wrote:
> Thanks for the responses.
>
> I'm coding entirely in C# for this, I'll look into the
> IConverterSession interface but would appreciate any hints/tips.
>
> I'm working with standalong .msg files.
>
> Also, I noticed an application called msgDetach which performs the
> required task but I'd prefer not to resort to foreign code in my
> solution.
>
> Thanks
>
date: Thu, 07 Aug 2008 22:35:25 +0530
author: Ashutosh Bhawasinka
Re: Working with .msg files that are attachments
Alternatively, if the .msg file is an embedded message (as an attachment
in a mail), then you need to do these
-Open the .msg file/attachment using IMessage::OpenAttach, here IMessage
will be of the message containing the .msg file
-Then call IAttach::OpenProperty requesting an IID_IMessage interface
-Now you again have a IMessage, which is of the embedded message, you
can do anything you do on a normal message.
Ashutosh Bhawasinka wrote:
> Use something like [this may not be the best way to. Use it at your
> own risk]
>
>
> #define _MSGSESS IMessage
> #include <imessage.h>
> ..
> ..
> ..then
> CComPtr<IMessage> pMessage;
> CComPtr<IStorage> pStorage;
> LPMSGSESS pMsgSession = NULL;
> LPMSGSESS pIMsg = NULL;
> HRESULT hRes;
> LPMALLOC pMalloc = MAPIGetDefaultMalloc();
> hRes = ::StgOpenStorage(L"c:\\a.msg",NULL, STGM_READWRITE |
> STGM_TRANSACTED,NULL,NULL,&pStorage);
> // Open an IMessage interface on an IStorage object
> if(FAILED(hRes) )
> return;
> //TODO: verify that CLSID is CLSID_MailMessage using ReadClassStg
>
> // Open an IMessage session.
> hRes = ::OpenIMsgSession(pMalloc, 0, &pMsgSession);
> if(FAILED(hRes) || !pMsgSession)
> {
> Debug(DebugLevel::Error,_T("Error [%#08x] from OpenIMsgSession
> - %s"),hRes, CMAPIHealper::GetErrorDetails(hRes));
> return ;
> }
>
> hRes = ::OpenIMsgOnIStg(pMsgSession, MAPIAllocateBuffer,
> MAPIAllocateMore, MAPIFreeBuffer, pMalloc, NULL, pStorage, NULL, 0, 0,
> &pIMsg);
> if(FAILED(hRes) || !pIMsg)
> {
> Debug(DebugLevel::Error,_T("Error [%#08x] from OpenIMsgSession
> - %s"),hRes, CMAPIHealper::GetErrorDetails(hRes));
> pMsgSession->Release();
> return ;
> }
> CMAPIHealper::DumpProperties(pIMsg);
> //release other interfaces...
>
> -> at this point you have a valid IMessage interface pIMsg, you can
> retrieve any properties...
>
> I just ran this code and I could see all the properties correctly. Now
> that you have an IMessage, you can read its content, its attachment in
> the usual MAPI way.
>
> Hope you can convert this to C#!
date: Thu, 07 Aug 2008 23:09:19 +0530
author: Ashutosh Bhawasinka
Re: Working with .msg files that are attachments
On 7 Aug, 18:39, Ashutosh Bhawasinka wrote:
> Alternatively, if the .msg file is an embedded message (as an attachment
> in a mail), then you need to do these
> -Open the .msg file/attachment using IMessage::OpenAttach, here IMessage
> will be of the message containing the .msg file
> -Then call IAttach::OpenProperty requesting an IID_IMessage interface
> -Now you again have a IMessage, which is of the embedded message, you
> can do anything you do on a normal message.
>
>
>
> Ashutosh Bhawasinka wrote:
> > Use something like [this may not be the best way to. Use it at your
> > own risk]
>
> > #define _MSGSESS IMessage
> > #include <imessage.h>
> > ..
> > ..
> > ..then
> > CComPtr<IMessage> pMessage;
> > CComPtr<IStorage> pStorage;
> > LPMSGSESS pMsgSession = NULL;
> > LPMSGSESS pIMsg = NULL;
> > HRESULT hRes;
> > LPMALLOC pMalloc = MAPIGetDefaultMalloc();
> > hRes = ::StgOpenStorage(L"c:\\a.msg",NULL, STGM_READWRITE |
> > STGM_TRANSACTED,NULL,NULL,&pStorage);
> > // Open an IMessage interface on an IStorage object
> > if(FAILED(hRes) )
> > return;
> > //TODO: verify that CLSID is CLSID_MailMessage using ReadClassStg
>
> > // Open an IMessage session.
> > hRes = ::OpenIMsgSession(pMalloc, 0, &pMsgSession);
> > if(FAILED(hRes) || !pMsgSession)
> > {
> > Debug(DebugLevel::Error,_T("Error [%#08x] from OpenIMsgSession
> > - %s"),hRes, CMAPIHealper::GetErrorDetails(hRes));
> > return ;
> > }
>
> > hRes = ::OpenIMsgOnIStg(pMsgSession, MAPIAllocateBuffer,
> > MAPIAllocateMore, MAPIFreeBuffer, pMalloc, NULL, pStorage, NULL, 0, 0,
> > &pIMsg);
> > if(FAILED(hRes) || !pIMsg)
> > {
> > Debug(DebugLevel::Error,_T("Error [%#08x] from OpenIMsgSession
> > - %s"),hRes, CMAPIHealper::GetErrorDetails(hRes));
> > pMsgSession->Release();
> > return ;
> > }
> > CMAPIHealper::DumpProperties(pIMsg);
> > //release other interfaces...
>
> > -> at this point you have a valid IMessage interface pIMsg, you can
> > retrieve any properties...
>
> > I just ran this code and I could see all the properties correctly. Now
> > that you have an IMessage, you can read its content, its attachment in
> > the usual MAPI way.
>
> > Hope you can convert this to C#!- Hide quoted text -
>
> - Show quoted text -
Thanks for that, the only reason I'm working with standalone .msg
files is because that was the only way MAPI was allowing to to extract
them. They were originally attached to other emails.
I will see how far I get with IMessage.
date: Fri, 8 Aug 2008 04:57:01 -0700 (PDT)
author: airwot4
Re: Working with .msg files that are attachments
On 8 Aug, 12:57, airwot4 wrote:
> On 7 Aug, 18:39, Ashutosh Bhawasinka wrote:
>
>
>
>
>
> > Alternatively, if the .msg file is an embedded message (as an attachment
> > in a mail), then you need to do these
> > -Open the .msg file/attachment using IMessage::OpenAttach, here IMessage
> > will be of the message containing the .msg file
> > -Then call IAttach::OpenProperty requesting an IID_IMessage interface
> > -Now you again have a IMessage, which is of the embedded message, you
> > can do anything you do on a normal message.
>
> > Ashutosh Bhawasinka wrote:
> > > Use something like [this may not be the best way to. Use it at your
> > > own risk]
>
> > > #define _MSGSESS IMessage
> > > #include <imessage.h>
> > > ..
> > > ..
> > > ..then
> > > CComPtr<IMessage> pMessage;
> > > CComPtr<IStorage> pStorage;
> > > LPMSGSESS pMsgSession = NULL;
> > > LPMSGSESS pIMsg = NULL;
> > > HRESULT hRes;
> > > LPMALLOC pMalloc = MAPIGetDefaultMalloc();
> > > hRes = ::StgOpenStorage(L"c:\\a.msg",NULL, STGM_READWRITE |
> > > STGM_TRANSACTED,NULL,NULL,&pStorage);
> > > // Open an IMessage interface on an IStorage object
> > > if(FAILED(hRes) )
> > > return;
> > > //TODO: verify that CLSID is CLSID_MailMessage using ReadClassStg
>
> > > // Open an IMessage session.
> > > hRes = ::OpenIMsgSession(pMalloc, 0, &pMsgSession);
> > > if(FAILED(hRes) || !pMsgSession)
> > > {
> > > Debug(DebugLevel::Error,_T("Error [%#08x] from OpenIMsgSession
> > > - %s"),hRes, CMAPIHealper::GetErrorDetails(hRes));
> > > return ;
> > > }
>
> > > hRes = ::OpenIMsgOnIStg(pMsgSession, MAPIAllocateBuffer,
> > > MAPIAllocateMore, MAPIFreeBuffer, pMalloc, NULL, pStorage, NULL, 0, 0> > > &pIMsg);
> > > if(FAILED(hRes) || !pIMsg)
> > > {
> > > Debug(DebugLevel::Error,_T("Error [%#08x] from OpenIMsgSession
> > > - %s"),hRes, CMAPIHealper::GetErrorDetails(hRes));
> > > pMsgSession->Release();
> > > return ;
> > > }
> > > CMAPIHealper::DumpProperties(pIMsg);
> > > //release other interfaces...
>
> > > -> at this point you have a valid IMessage interface pIMsg, you can
> > > retrieve any properties...
>
> > > I just ran this code and I could see all the properties correctly. Now
> > > that you have an IMessage, you can read its content, its attachment in
> > > the usual MAPI way.
>
> > > Hope you can convert this to C#!- Hide quoted text -
>
> > - Show quoted text -
>
> Thanks for that, the only reason I'm working with standalone .msg
> files is because that was the only way MAPI was allowing to to extract
> them. They were originally attached to other emails.
>
> I will see how far I get with IMessage.- Hide quoted text -
>
> - Show quoted text -
I've had little luck with this so far, I was hoping to find some C#
examples of this interface being used but have been unable to. I have
little experience of working with interfaces so don't think I'll be
able to muddle through this until I do, is there any resources you
could recommend for reading up on this?
date: Fri, 8 Aug 2008 05:40:37 -0700 (PDT)
author: airwot4
Re: Working with .msg files that are attachments
If you are using OOM, the only way to import MSG file is to call
Application.CreateItemFromTemplate.
<plug>
Redemption (url below) supports both opening the standalone MSG files (see
RDOSession.GetMessageFromMsgFIle) and importing the contents of any MSG file
using RDOMail.Import.
</plug>
--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"airwot4" wrote in message
news:49167791-358d-4a4c-b7d2-a4ba08534d54@d1g2000hsg.googlegroups.com...
> On 8 Aug, 15:54, Ashutosh Bhawasinka wrote:
>> What exactly you are trying to do??
>> I guess you already have the code in C# to read open the message and its
>> attachment!! So, if you tell us where you are stuck, maybe we can help.
>>
>> If you are using functions like StgOpenStorage, OpenIMsgSession,
>> OpenIMsgOnIStg, you can use P/Invoke
>
> I'm using the Microsoft.Office.Interop.Outlook library to end up with
> an Outlook.Attachment from a message. The only function I can find to
> do this is Attachment.SaveAsFile. As I am working with a message
> attached to a message this saves the .msg file to disk. I would like
> to be able to create a Outlook._MailItem from the .msg file in order
> to extract the attachment from that.
date: Mon, 11 Aug 2008 11:53:17 -0700
author: Dmitry Streblechenko
Re: Working with .msg files that are attachments
On 11 Aug, 19:53, "Dmitry Streblechenko" wrote:
> If you are using OOM, the only way to import MSG file is to call
> Application.CreateItemFromTemplate.
> <plug>
> Redemption (url below) supports both opening the standalone MSG files (see
> RDOSession.GetMessageFromMsgFIle) and importing the contents of any MSG file
> using RDOMail.Import.
> </plug>
>
> --
> Dmitry Streblechenko (MVP)http://www.dimastr.com/
> OutlookSpy - Outlook, CDO
> and MAPI Developer Tool
> -"airwot4" wrote in message
>
> news:49167791-358d-4a4c-b7d2-a4ba08534d54@d1g2000hsg.googlegroups.com...
>
>
>
> > On 8 Aug, 15:54, Ashutosh Bhawasinka wrote:
> >> What exactly you are trying to do??
> >> I guess you already have the code in C# to read open the message and its
> >> attachment!! So, if you tell us where you are stuck, maybe we can help> >> If you are using functions like StgOpenStorage, OpenIMsgSession,
> >> OpenIMsgOnIStg, you can use P/Invoke
>
> > I'm using the Microsoft.Office.Interop.Outlook library to end up with
> > an Outlook.Attachment from a message. The only function I can find to
> > do this is Attachment.SaveAsFile. As I am working with a message
> > attached to a message this saves the .msg file to disk. I would like
> > to be able to create a Outlook._MailItem from the .msg file in order
> > to extract the attachment from that.- Hide quoted text -
>
> - Show quoted text -
That's great, thank you. Redemption made it very easy.
date: Tue, 12 Aug 2008 04:55:16 -0700 (PDT)
author: airwot4
Re: Working with .msg files that are attachments
Hi,
I am using RDOSession.GetMessageFromMsgFIle to get RDOMail. I am having 2
attachments in this Mail. Once I get the names of the attachments, I am not
able to use the attachments again. I am getting exception "Error in
IMessage.OpenAttach: MAPI_E_NO_ACCESS". Can anybody please help me.
Thanks,
Zaheer
"Dmitry Streblechenko" wrote:
> If you are using OOM, the only way to import MSG file is to call
> Application.CreateItemFromTemplate.
> <plug>
> Redemption (url below) supports both opening the standalone MSG files (see
> RDOSession.GetMessageFromMsgFIle) and importing the contents of any MSG file
> using RDOMail.Import.
> </plug>
>
> --
> Dmitry Streblechenko (MVP)
> http://www.dimastr.com/
> OutlookSpy - Outlook, CDO
> and MAPI Developer Tool
> -
> "airwot4" wrote in message
> news:49167791-358d-4a4c-b7d2-a4ba08534d54@d1g2000hsg.googlegroups.com...
> > On 8 Aug, 15:54, Ashutosh Bhawasinka wrote:
> >> What exactly you are trying to do??
> >> I guess you already have the code in C# to read open the message and its
> >> attachment!! So, if you tell us where you are stuck, maybe we can help.
> >>
> >> If you are using functions like StgOpenStorage, OpenIMsgSession,
> >> OpenIMsgOnIStg, you can use P/Invoke
> >
> > I'm using the Microsoft.Office.Interop.Outlook library to end up with
> > an Outlook.Attachment from a message. The only function I can find to
> > do this is Attachment.SaveAsFile. As I am working with a message
> > attached to a message this saves the .msg file to disk. I would like
> > to be able to create a Outlook._MailItem from the .msg file in order
> > to extract the attachment from that.
>
>
>
date: Fri, 3 Oct 2008 08:34:05 -0700
author: Zaheer Syed Zaheer
Re: Working with .msg files that are attachments
Messages created MSG files created on top of MSG files won't let you reopen
the attachmeent table (IMesage::GetAttachmentTable until your release the
first instance.
Cache the returned from RDOMail.Attachments and do nto use multipel dot
notation:
set Attachments = YourRDOMail.Attachments
if Attachments.Count > 0 Then
MsgBox Attachments.Items(i).FileName
End If
set Attachments = Nothing 'release it
--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"Zaheer Syed" <Zaheer Syed@discussions.microsoft.com> wrote in message
news:D1AA1825-4F06-4A7A-A500-7520A2FDC89B@microsoft.com...
> Hi,
> I am using RDOSession.GetMessageFromMsgFIle to get RDOMail. I am having 2
> attachments in this Mail. Once I get the names of the attachments, I am
> not
> able to use the attachments again. I am getting exception "Error in
> IMessage.OpenAttach: MAPI_E_NO_ACCESS". Can anybody please help me.
>
> Thanks,
> Zaheer
>
> "Dmitry Streblechenko" wrote:
>
>> If you are using OOM, the only way to import MSG file is to call
>> Application.CreateItemFromTemplate.
>> <plug>
>> Redemption (url below) supports both opening the standalone MSG files
>> (see
>> RDOSession.GetMessageFromMsgFIle) and importing the contents of any MSG
>> file
>> using RDOMail.Import.
>> </plug>
>>
>> --
>> Dmitry Streblechenko (MVP)
>> http://www.dimastr.com/
>> OutlookSpy - Outlook, CDO
>> and MAPI Developer Tool
>> -
>> "airwot4" wrote in message
>> news:49167791-358d-4a4c-b7d2-a4ba08534d54@d1g2000hsg.googlegroups.com...
>> > On 8 Aug, 15:54, Ashutosh Bhawasinka wrote:
>> >> What exactly you are trying to do??
>> >> I guess you already have the code in C# to read open the message and
>> >> its
>> >> attachment!! So, if you tell us where you are stuck, maybe we can
>> >> help.
>> >>
>> >> If you are using functions like StgOpenStorage, OpenIMsgSession,
>> >> OpenIMsgOnIStg, you can use P/Invoke
>> >
>> > I'm using the Microsoft.Office.Interop.Outlook library to end up with
>> > an Outlook.Attachment from a message. The only function I can find to
>> > do this is Attachment.SaveAsFile. As I am working with a message
>> > attached to a message this saves the .msg file to disk. I would like
>> > to be able to create a Outlook._MailItem from the .msg file in order
>> > to extract the attachment from that.
>>
>>
>>
date: Mon, 6 Oct 2008 15:01:58 -0700
author: Dmitry Streblechenko
|
|