Group:  Microsoft Outlook » microsoft.public.outlook.program_addins
Thread: Custom _MailItem for Custom Store

Geek News

Custom _MailItem for Custom Store
Tom at GSD 2/15/2007 3:56:18 PM
Hi,

I have created an ATL C++ Outlook plug-in for Outlook 2003.

I would like to create a custom _MailItem object; that I can control all of
the properties at any time. Is this possible?

I have created my own store with custom folders for custom events. It so
happens that the _MailItem object has all of the properties that I need for
custom object within my folder array. I want to be able to set the date
properties, to & from properties, read and unread properties, and a few other
properties. When I create the _MailItem object I cannot gain access to a few
of the properties without performing ugly procedures – does anybody have any
suggestions?

I have a method that will work but it is really ugly and I want to make this
a little more robust. Any suggestions would be greatly appreciated.

Thanks,
Tom -

Re: Custom _MailItem for Custom Store
"Dmitry Streblechenko" <dmitry[ at ]dimastr.com> 2/15/2007 5:53:57 PM
Do you mean you wrote a custom MAPI store provider or that you added a PST
store where you store your custom items?
What prevents you from creating your own class that references MailItem
internally and exposes your custom properties?

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

"Tom at GSD" <TomatGSD[ at ]discussions.microsoft.com> wrote in message
news:248A2DE5-CA0D-426E-A3D8-0D4F5B59C4CA[ at ]microsoft.com...
[Quoted Text]
> Hi,
>
> I have created an ATL C++ Outlook plug-in for Outlook 2003.
>
> I would like to create a custom _MailItem object; that I can control all
> of
> the properties at any time. Is this possible?
>
> I have created my own store with custom folders for custom events. It so
> happens that the _MailItem object has all of the properties that I need
> for
> custom object within my folder array. I want to be able to set the date
> properties, to & from properties, read and unread properties, and a few
> other
> properties. When I create the _MailItem object I cannot gain access to a
> few
> of the properties without performing ugly procedures - does anybody have
> any
> suggestions?
>
> I have a method that will work but it is really ugly and I want to make
> this
> a little more robust. Any suggestions would be greatly appreciated.
>
> Thanks,
> Tom -
>


Re: Custom _MailItem for Custom Store
Tom at GSD 2/15/2007 6:07:43 PM
I added a PST file that will store my custom items.

I have created a _MailItem and I cannot set the date or any of the email
address properties (sender and recipient). It seems like most of the
properties are not accessible until I send the message.

I am creating a mail item and moving it to my custom folder. I want to be
able to set all properties (through MAPI or the Outlook classes) at any time.
When I try to set properties through MAPI my functionality returns a success
(S_OK) - but the properties are never set. Am I missing something?

BTW - the book you recommended is excellent. (Inside MAPI)



"Dmitry Streblechenko" wrote:

[Quoted Text]
> Do you mean you wrote a custom MAPI store provider or that you added a PST
> store where you store your custom items?
> What prevents you from creating your own class that references MailItem
> internally and exposes your custom properties?
>
> Dmitry Streblechenko (MVP)
> http://www.dimastr.com/
> OutlookSpy - Outlook, CDO
> and MAPI Developer Tool
>
> "Tom at GSD" <TomatGSD[ at ]discussions.microsoft.com> wrote in message
> news:248A2DE5-CA0D-426E-A3D8-0D4F5B59C4CA[ at ]microsoft.com...
> > Hi,
> >
> > I have created an ATL C++ Outlook plug-in for Outlook 2003.
> >
> > I would like to create a custom _MailItem object; that I can control all
> > of
> > the properties at any time. Is this possible?
> >
> > I have created my own store with custom folders for custom events. It so
> > happens that the _MailItem object has all of the properties that I need
> > for
> > custom object within my folder array. I want to be able to set the date
> > properties, to & from properties, read and unread properties, and a few
> > other
> > properties. When I create the _MailItem object I cannot gain access to a
> > few
> > of the properties without performing ugly procedures - does anybody have
> > any
> > suggestions?
> >
> > I have a method that will work but it is really ugly and I want to make
> > this
> > a little more robust. Any suggestions would be greatly appreciated.
> >
> > Thanks,
> > Tom -
> >
>
>
>
Re: Custom _MailItem for Custom Store
"Dmitry Streblechenko" <dmitry[ at ]dimastr.com> 2/15/2007 6:17:56 PM
Sender properies are not settable in the Outlook Obejct Model.
You really need to show your code.

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

"Tom at GSD" <TomatGSD[ at ]discussions.microsoft.com> wrote in message
news:91EA64D3-D394-4D9C-9D21-87DCC457EBDE[ at ]microsoft.com...
[Quoted Text]
>I added a PST file that will store my custom items.
>
> I have created a _MailItem and I cannot set the date or any of the email
> address properties (sender and recipient). It seems like most of the
> properties are not accessible until I send the message.
>
> I am creating a mail item and moving it to my custom folder. I want to be
> able to set all properties (through MAPI or the Outlook classes) at any
> time.
> When I try to set properties through MAPI my functionality returns a
> success
> (S_OK) - but the properties are never set. Am I missing something?
>
> BTW - the book you recommended is excellent. (Inside MAPI)
>
>
>
> "Dmitry Streblechenko" wrote:
>
>> Do you mean you wrote a custom MAPI store provider or that you added a
>> PST
>> store where you store your custom items?
>> What prevents you from creating your own class that references MailItem
>> internally and exposes your custom properties?
>>
>> Dmitry Streblechenko (MVP)
>> http://www.dimastr.com/
>> OutlookSpy - Outlook, CDO
>> and MAPI Developer Tool
>>
>> "Tom at GSD" <TomatGSD[ at ]discussions.microsoft.com> wrote in message
>> news:248A2DE5-CA0D-426E-A3D8-0D4F5B59C4CA[ at ]microsoft.com...
>> > Hi,
>> >
>> > I have created an ATL C++ Outlook plug-in for Outlook 2003.
>> >
>> > I would like to create a custom _MailItem object; that I can control
>> > all
>> > of
>> > the properties at any time. Is this possible?
>> >
>> > I have created my own store with custom folders for custom events. It
>> > so
>> > happens that the _MailItem object has all of the properties that I need
>> > for
>> > custom object within my folder array. I want to be able to set the date
>> > properties, to & from properties, read and unread properties, and a few
>> > other
>> > properties. When I create the _MailItem object I cannot gain access to
>> > a
>> > few
>> > of the properties without performing ugly procedures - does anybody
>> > have
>> > any
>> > suggestions?
>> >
>> > I have a method that will work but it is really ugly and I want to make
>> > this
>> > a little more robust. Any suggestions would be greatly appreciated.
>> >
>> > Thanks,
>> > Tom -
>> >
>>
>>
>>


Re: Custom _MailItem for Custom Store
Tom at GSD 2/15/2007 6:36:17 PM
This is the code I am usiing through MAPI. I cut and pasted some of my code.

void CreateCustomMailItem()
{
// Create new mail item
CComQIPtr<Outlook::_MailItem> spCustomItem =
m_spApplication->CreateItem(Outlook::olMailItem);

// Get message component
IUnknownPtr pUnk = spCustomItem->GetMAPIOBJECT();
CComQIPtr<IMessage, &IID_IMessage> spMessage(pUnk);

// Set MAPI property (I hard coded a MAPI property for this example - I
have tried many)
SetProperty(spMessage, _T("blah[ at ]blah.com") ;

// Move item to custom folder
spCustomItem->Move(m_spCustomEventFolder);
}

HRESULT SetProperty(CComQIPtr<IMessage, &IID_IMessage> spMessage, LPCTSTR
szValue)
{
HRESULT hr;
MAPINAMEID NamedProp;
NamedProp.ulKind = MNID_STRING;
MAPINAMEID* pNamedProp = &NamedProp;
LPSPropTagArray lpTags = 0;
SPropValue prop;
char szVal[500] = {NULL};

#ifdef _UNICODE
char* pAnsiData = NULL;
UnicodeToAnsi(szValue, &pAnsiData);
strcpy(szVal, pAnsiData);
CoTaskMemFree(pAnsiData);
#else
strcpy(szVal, szValue);
#endif
// tried numerous properties
prop.ulPropTag = PROP_TAG(PT_STRING8,PROP_ID(PR_SENDER_EMAIL_ADDRESS_A));
prop.Value.lpszA = (LPSTR)szVal;

// Return S_OK all the time - but the values never change
hr = HrSetOneProp((LPMAPIPROP)(IUnknown*)spMessage, &prop );
MAPIFreeBuffer(lpTags);

return hr;
}






"Dmitry Streblechenko" wrote:

[Quoted Text]
> Sender properies are not settable in the Outlook Obejct Model.
> You really need to show your code.
>
> Dmitry Streblechenko (MVP)
> http://www.dimastr.com/
> OutlookSpy - Outlook, CDO
> and MAPI Developer Tool
>
> "Tom at GSD" <TomatGSD[ at ]discussions.microsoft.com> wrote in message
> news:91EA64D3-D394-4D9C-9D21-87DCC457EBDE[ at ]microsoft.com...
> >I added a PST file that will store my custom items.
> >
> > I have created a _MailItem and I cannot set the date or any of the email
> > address properties (sender and recipient). It seems like most of the
> > properties are not accessible until I send the message.
> >
> > I am creating a mail item and moving it to my custom folder. I want to be
> > able to set all properties (through MAPI or the Outlook classes) at any
> > time.
> > When I try to set properties through MAPI my functionality returns a
> > success
> > (S_OK) - but the properties are never set. Am I missing something?
> >
> > BTW - the book you recommended is excellent. (Inside MAPI)
> >
> >
> >
> > "Dmitry Streblechenko" wrote:
> >
> >> Do you mean you wrote a custom MAPI store provider or that you added a
> >> PST
> >> store where you store your custom items?
> >> What prevents you from creating your own class that references MailItem
> >> internally and exposes your custom properties?
> >>
> >> Dmitry Streblechenko (MVP)
> >> http://www.dimastr.com/
> >> OutlookSpy - Outlook, CDO
> >> and MAPI Developer Tool
> >>
> >> "Tom at GSD" <TomatGSD[ at ]discussions.microsoft.com> wrote in message
> >> news:248A2DE5-CA0D-426E-A3D8-0D4F5B59C4CA[ at ]microsoft.com...
> >> > Hi,
> >> >
> >> > I have created an ATL C++ Outlook plug-in for Outlook 2003.
> >> >
> >> > I would like to create a custom _MailItem object; that I can control
> >> > all
> >> > of
> >> > the properties at any time. Is this possible?
> >> >
> >> > I have created my own store with custom folders for custom events. It
> >> > so
> >> > happens that the _MailItem object has all of the properties that I need
> >> > for
> >> > custom object within my folder array. I want to be able to set the date
> >> > properties, to & from properties, read and unread properties, and a few
> >> > other
> >> > properties. When I create the _MailItem object I cannot gain access to
> >> > a
> >> > few
> >> > of the properties without performing ugly procedures - does anybody
> >> > have
> >> > any
> >> > suggestions?
> >> >
> >> > I have a method that will work but it is really ugly and I want to make
> >> > this
> >> > a little more robust. Any suggestions would be greatly appreciated.
> >> >
> >> > Thanks,
> >> > Tom -
> >> >
> >>
> >>
> >>
>
>
>
Re: Custom _MailItem for Custom Store
"Dmitry Streblechenko" <dmitry[ at ]dimastr.com> 2/15/2007 8:43:16 PM
Save the item (spCustomItem->Save()) before moving it.

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

"Tom at GSD" <TomatGSD[ at ]discussions.microsoft.com> wrote in message
news:99B8E40F-4708-4DAB-AAB1-E39B9408677C[ at ]microsoft.com...
[Quoted Text]
> This is the code I am usiing through MAPI. I cut and pasted some of my
> code.
>
> void CreateCustomMailItem()
> {
> // Create new mail item
> CComQIPtr<Outlook::_MailItem> spCustomItem =
> m_spApplication->CreateItem(Outlook::olMailItem);
>
> // Get message component
> IUnknownPtr pUnk = spCustomItem->GetMAPIOBJECT();
> CComQIPtr<IMessage, &IID_IMessage> spMessage(pUnk);
>
> // Set MAPI property (I hard coded a MAPI property for this example - I
> have tried many)
> SetProperty(spMessage, _T("blah[ at ]blah.com") ;
>
> // Move item to custom folder
> spCustomItem->Move(m_spCustomEventFolder);
> }
>
> HRESULT SetProperty(CComQIPtr<IMessage, &IID_IMessage> spMessage, LPCTSTR
> szValue)
> {
> HRESULT hr;
> MAPINAMEID NamedProp;
> NamedProp.ulKind = MNID_STRING;
> MAPINAMEID* pNamedProp = &NamedProp;
> LPSPropTagArray lpTags = 0;
> SPropValue prop;
> char szVal[500] = {NULL};
>
> #ifdef _UNICODE
> char* pAnsiData = NULL;
> UnicodeToAnsi(szValue, &pAnsiData);
> strcpy(szVal, pAnsiData);
> CoTaskMemFree(pAnsiData);
> #else
> strcpy(szVal, szValue);
> #endif
> // tried numerous properties
> prop.ulPropTag = PROP_TAG(PT_STRING8,PROP_ID(PR_SENDER_EMAIL_ADDRESS_A));
> prop.Value.lpszA = (LPSTR)szVal;
>
> // Return S_OK all the time - but the values never change
> hr = HrSetOneProp((LPMAPIPROP)(IUnknown*)spMessage, &prop );
> MAPIFreeBuffer(lpTags);
>
> return hr;
> }
>
>
>
>
>
>
> "Dmitry Streblechenko" wrote:
>
>> Sender properies are not settable in the Outlook Obejct Model.
>> You really need to show your code.
>>
>> Dmitry Streblechenko (MVP)
>> http://www.dimastr.com/
>> OutlookSpy - Outlook, CDO
>> and MAPI Developer Tool
>>
>> "Tom at GSD" <TomatGSD[ at ]discussions.microsoft.com> wrote in message
>> news:91EA64D3-D394-4D9C-9D21-87DCC457EBDE[ at ]microsoft.com...
>> >I added a PST file that will store my custom items.
>> >
>> > I have created a _MailItem and I cannot set the date or any of the
>> > email
>> > address properties (sender and recipient). It seems like most of the
>> > properties are not accessible until I send the message.
>> >
>> > I am creating a mail item and moving it to my custom folder. I want to
>> > be
>> > able to set all properties (through MAPI or the Outlook classes) at any
>> > time.
>> > When I try to set properties through MAPI my functionality returns a
>> > success
>> > (S_OK) - but the properties are never set. Am I missing something?
>> >
>> > BTW - the book you recommended is excellent. (Inside MAPI)
>> >
>> >
>> >
>> > "Dmitry Streblechenko" wrote:
>> >
>> >> Do you mean you wrote a custom MAPI store provider or that you added a
>> >> PST
>> >> store where you store your custom items?
>> >> What prevents you from creating your own class that references
>> >> MailItem
>> >> internally and exposes your custom properties?
>> >>
>> >> Dmitry Streblechenko (MVP)
>> >> http://www.dimastr.com/
>> >> OutlookSpy - Outlook, CDO
>> >> and MAPI Developer Tool
>> >>
>> >> "Tom at GSD" <TomatGSD[ at ]discussions.microsoft.com> wrote in message
>> >> news:248A2DE5-CA0D-426E-A3D8-0D4F5B59C4CA[ at ]microsoft.com...
>> >> > Hi,
>> >> >
>> >> > I have created an ATL C++ Outlook plug-in for Outlook 2003.
>> >> >
>> >> > I would like to create a custom _MailItem object; that I can control
>> >> > all
>> >> > of
>> >> > the properties at any time. Is this possible?
>> >> >
>> >> > I have created my own store with custom folders for custom events.
>> >> > It
>> >> > so
>> >> > happens that the _MailItem object has all of the properties that I
>> >> > need
>> >> > for
>> >> > custom object within my folder array. I want to be able to set the
>> >> > date
>> >> > properties, to & from properties, read and unread properties, and a
>> >> > few
>> >> > other
>> >> > properties. When I create the _MailItem object I cannot gain access
>> >> > to
>> >> > a
>> >> > few
>> >> > of the properties without performing ugly procedures - does anybody
>> >> > have
>> >> > any
>> >> > suggestions?
>> >> >
>> >> > I have a method that will work but it is really ugly and I want to
>> >> > make
>> >> > this
>> >> > a little more robust. Any suggestions would be greatly appreciated.
>> >> >
>> >> > Thanks,
>> >> > Tom -
>> >> >
>> >>
>> >>
>> >>
>>
>>
>>


Re: Custom _MailItem for Custom Store
Tom at GSD 2/16/2007 3:23:08 PM
Thanks for your reply.

I was at one time saving the _MailItem and I put the call back in my code -
but the save does not seem to help as far as setting the sent parameters. In
other words I am still not able to setup the _MailItem to get it to look like
it already has been sent. What MAPI properties will cause the _MailItem to
look as if it has been sent?


"Dmitry Streblechenko" wrote:

[Quoted Text]
> Save the item (spCustomItem->Save()) before moving it.
>
> Dmitry Streblechenko (MVP)
> http://www.dimastr.com/
> OutlookSpy - Outlook, CDO
> and MAPI Developer Tool
>
> "Tom at GSD" <TomatGSD[ at ]discussions.microsoft.com> wrote in message
> news:99B8E40F-4708-4DAB-AAB1-E39B9408677C[ at ]microsoft.com...
> > This is the code I am usiing through MAPI. I cut and pasted some of my
> > code.
> >
> > void CreateCustomMailItem()
> > {
> > // Create new mail item
> > CComQIPtr<Outlook::_MailItem> spCustomItem =
> > m_spApplication->CreateItem(Outlook::olMailItem);
> >
> > // Get message component
> > IUnknownPtr pUnk = spCustomItem->GetMAPIOBJECT();
> > CComQIPtr<IMessage, &IID_IMessage> spMessage(pUnk);
> >
> > // Set MAPI property (I hard coded a MAPI property for this example - I
> > have tried many)
> > SetProperty(spMessage, _T("blah[ at ]blah.com") ;
> >
> > // Move item to custom folder
> > spCustomItem->Move(m_spCustomEventFolder);
> > }
> >
> > HRESULT SetProperty(CComQIPtr<IMessage, &IID_IMessage> spMessage, LPCTSTR
> > szValue)
> > {
> > HRESULT hr;
> > MAPINAMEID NamedProp;
> > NamedProp.ulKind = MNID_STRING;
> > MAPINAMEID* pNamedProp = &NamedProp;
> > LPSPropTagArray lpTags = 0;
> > SPropValue prop;
> > char szVal[500] = {NULL};
> >
> > #ifdef _UNICODE
> > char* pAnsiData = NULL;
> > UnicodeToAnsi(szValue, &pAnsiData);
> > strcpy(szVal, pAnsiData);
> > CoTaskMemFree(pAnsiData);
> > #else
> > strcpy(szVal, szValue);
> > #endif
> > // tried numerous properties
> > prop.ulPropTag = PROP_TAG(PT_STRING8,PROP_ID(PR_SENDER_EMAIL_ADDRESS_A));
> > prop.Value.lpszA = (LPSTR)szVal;
> >
> > // Return S_OK all the time - but the values never change
> > hr = HrSetOneProp((LPMAPIPROP)(IUnknown*)spMessage, &prop );
> > MAPIFreeBuffer(lpTags);
> >
> > return hr;
> > }
> >
> >
> >
> >
> >
> >
> > "Dmitry Streblechenko" wrote:
> >
> >> Sender properies are not settable in the Outlook Obejct Model.
> >> You really need to show your code.
> >>
> >> Dmitry Streblechenko (MVP)
> >> http://www.dimastr.com/
> >> OutlookSpy - Outlook, CDO
> >> and MAPI Developer Tool
> >>
> >> "Tom at GSD" <TomatGSD[ at ]discussions.microsoft.com> wrote in message
> >> news:91EA64D3-D394-4D9C-9D21-87DCC457EBDE[ at ]microsoft.com...
> >> >I added a PST file that will store my custom items.
> >> >
> >> > I have created a _MailItem and I cannot set the date or any of the
> >> > email
> >> > address properties (sender and recipient). It seems like most of the
> >> > properties are not accessible until I send the message.
> >> >
> >> > I am creating a mail item and moving it to my custom folder. I want to
> >> > be
> >> > able to set all properties (through MAPI or the Outlook classes) at any
> >> > time.
> >> > When I try to set properties through MAPI my functionality returns a
> >> > success
> >> > (S_OK) - but the properties are never set. Am I missing something?
> >> >
> >> > BTW - the book you recommended is excellent. (Inside MAPI)
> >> >
> >> >
> >> >
> >> > "Dmitry Streblechenko" wrote:
> >> >
> >> >> Do you mean you wrote a custom MAPI store provider or that you added a
> >> >> PST
> >> >> store where you store your custom items?
> >> >> What prevents you from creating your own class that references
> >> >> MailItem
> >> >> internally and exposes your custom properties?
> >> >>
> >> >> Dmitry Streblechenko (MVP)
> >> >> http://www.dimastr.com/
> >> >> OutlookSpy - Outlook, CDO
> >> >> and MAPI Developer Tool
> >> >>
> >> >> "Tom at GSD" <TomatGSD[ at ]discussions.microsoft.com> wrote in message
> >> >> news:248A2DE5-CA0D-426E-A3D8-0D4F5B59C4CA[ at ]microsoft.com...
> >> >> > Hi,
> >> >> >
> >> >> > I have created an ATL C++ Outlook plug-in for Outlook 2003.
> >> >> >
> >> >> > I would like to create a custom _MailItem object; that I can control
> >> >> > all
> >> >> > of
> >> >> > the properties at any time. Is this possible?
> >> >> >
> >> >> > I have created my own store with custom folders for custom events.
> >> >> > It
> >> >> > so
> >> >> > happens that the _MailItem object has all of the properties that I
> >> >> > need
> >> >> > for
> >> >> > custom object within my folder array. I want to be able to set the
> >> >> > date
> >> >> > properties, to & from properties, read and unread properties, and a
> >> >> > few
> >> >> > other
> >> >> > properties. When I create the _MailItem object I cannot gain access
> >> >> > to
> >> >> > a
> >> >> > few
> >> >> > of the properties without performing ugly procedures - does anybody
> >> >> > have
> >> >> > any
> >> >> > suggestions?
> >> >> >
> >> >> > I have a method that will work but it is really ugly and I want to
> >> >> > make
> >> >> > this
> >> >> > a little more robust. Any suggestions would be greatly appreciated.
> >> >> >
> >> >> > Thanks,
> >> >> > Tom -
> >> >> >
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>
>
>
>
Re: Custom _MailItem for Custom Store
"Dmitry Streblechenko" <dmitry[ at ]dimastr.com> 2/16/2007 5:42:11 PM
Setting the sender related properties will have absolutely no effect on the
sent/unsent state. It is controlled by the MSGFLAG_UNSENT bit in
PR_MESSAGE_FLAGS. The bit can be modified only before the message is saved
for the every first time. As long as you are using OOM, you won't be able to
modify PR_MESSAGE_FLAGS through the MAPIOBJECT property because
MailItem.Save will reset the flag when Save is called for the very first
time.
One possible workaround is to create a post item ("IPM.Post", it is created
in the sent state), then reset the MessageClass property back to "IPM.Note"
and delete the PR_ICON_INDEX property -
http://www.dimastr.com/redemption/faq.htm#8

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

"Tom at GSD" <TomatGSD[ at ]discussions.microsoft.com> wrote in message
news:C1E4D26A-48CE-4D7F-B78C-9E053FBA2C71[ at ]microsoft.com...
[Quoted Text]
> Thanks for your reply.
>
> I was at one time saving the _MailItem and I put the call back in my
> code -
> but the save does not seem to help as far as setting the sent parameters.
> In
> other words I am still not able to setup the _MailItem to get it to look
> like
> it already has been sent. What MAPI properties will cause the _MailItem to
> look as if it has been sent?
>
>
> "Dmitry Streblechenko" wrote:
>
>> Save the item (spCustomItem->Save()) before moving it.
>>
>> Dmitry Streblechenko (MVP)
>> http://www.dimastr.com/
>> OutlookSpy - Outlook, CDO
>> and MAPI Developer Tool
>>
>> "Tom at GSD" <TomatGSD[ at ]discussions.microsoft.com> wrote in message
>> news:99B8E40F-4708-4DAB-AAB1-E39B9408677C[ at ]microsoft.com...
>> > This is the code I am usiing through MAPI. I cut and pasted some of my
>> > code.
>> >
>> > void CreateCustomMailItem()
>> > {
>> > // Create new mail item
>> > CComQIPtr<Outlook::_MailItem> spCustomItem =
>> > m_spApplication->CreateItem(Outlook::olMailItem);
>> >
>> > // Get message component
>> > IUnknownPtr pUnk = spCustomItem->GetMAPIOBJECT();
>> > CComQIPtr<IMessage, &IID_IMessage> spMessage(pUnk);
>> >
>> > // Set MAPI property (I hard coded a MAPI property for this example - I
>> > have tried many)
>> > SetProperty(spMessage, _T("blah[ at ]blah.com") ;
>> >
>> > // Move item to custom folder
>> > spCustomItem->Move(m_spCustomEventFolder);
>> > }
>> >
>> > HRESULT SetProperty(CComQIPtr<IMessage, &IID_IMessage> spMessage,
>> > LPCTSTR
>> > szValue)
>> > {
>> > HRESULT hr;
>> > MAPINAMEID NamedProp;
>> > NamedProp.ulKind = MNID_STRING;
>> > MAPINAMEID* pNamedProp = &NamedProp;
>> > LPSPropTagArray lpTags = 0;
>> > SPropValue prop;
>> > char szVal[500] = {NULL};
>> >
>> > #ifdef _UNICODE
>> > char* pAnsiData = NULL;
>> > UnicodeToAnsi(szValue, &pAnsiData);
>> > strcpy(szVal, pAnsiData);
>> > CoTaskMemFree(pAnsiData);
>> > #else
>> > strcpy(szVal, szValue);
>> > #endif
>> > // tried numerous properties
>> > prop.ulPropTag =
>> > PROP_TAG(PT_STRING8,PROP_ID(PR_SENDER_EMAIL_ADDRESS_A));
>> > prop.Value.lpszA = (LPSTR)szVal;
>> >
>> > // Return S_OK all the time - but the values never change
>> > hr = HrSetOneProp((LPMAPIPROP)(IUnknown*)spMessage, &prop );
>> > MAPIFreeBuffer(lpTags);
>> >
>> > return hr;
>> > }
>> >
>> >
>> >
>> >
>> >
>> >
>> > "Dmitry Streblechenko" wrote:
>> >
>> >> Sender properies are not settable in the Outlook Obejct Model.
>> >> You really need to show your code.
>> >>
>> >> Dmitry Streblechenko (MVP)
>> >> http://www.dimastr.com/
>> >> OutlookSpy - Outlook, CDO
>> >> and MAPI Developer Tool
>> >>
>> >> "Tom at GSD" <TomatGSD[ at ]discussions.microsoft.com> wrote in message
>> >> news:91EA64D3-D394-4D9C-9D21-87DCC457EBDE[ at ]microsoft.com...
>> >> >I added a PST file that will store my custom items.
>> >> >
>> >> > I have created a _MailItem and I cannot set the date or any of the
>> >> > email
>> >> > address properties (sender and recipient). It seems like most of the
>> >> > properties are not accessible until I send the message.
>> >> >
>> >> > I am creating a mail item and moving it to my custom folder. I want
>> >> > to
>> >> > be
>> >> > able to set all properties (through MAPI or the Outlook classes) at
>> >> > any
>> >> > time.
>> >> > When I try to set properties through MAPI my functionality returns a
>> >> > success
>> >> > (S_OK) - but the properties are never set. Am I missing something?
>> >> >
>> >> > BTW - the book you recommended is excellent. (Inside MAPI)
>> >> >
>> >> >
>> >> >
>> >> > "Dmitry Streblechenko" wrote:
>> >> >
>> >> >> Do you mean you wrote a custom MAPI store provider or that you
>> >> >> added a
>> >> >> PST
>> >> >> store where you store your custom items?
>> >> >> What prevents you from creating your own class that references
>> >> >> MailItem
>> >> >> internally and exposes your custom properties?
>> >> >>
>> >> >> Dmitry Streblechenko (MVP)
>> >> >> http://www.dimastr.com/
>> >> >> OutlookSpy - Outlook, CDO
>> >> >> and MAPI Developer Tool
>> >> >>
>> >> >> "Tom at GSD" <TomatGSD[ at ]discussions.microsoft.com> wrote in message
>> >> >> news:248A2DE5-CA0D-426E-A3D8-0D4F5B59C4CA[ at ]microsoft.com...
>> >> >> > Hi,
>> >> >> >
>> >> >> > I have created an ATL C++ Outlook plug-in for Outlook 2003.
>> >> >> >
>> >> >> > I would like to create a custom _MailItem object; that I can
>> >> >> > control
>> >> >> > all
>> >> >> > of
>> >> >> > the properties at any time. Is this possible?
>> >> >> >
>> >> >> > I have created my own store with custom folders for custom
>> >> >> > events.
>> >> >> > It
>> >> >> > so
>> >> >> > happens that the _MailItem object has all of the properties that
>> >> >> > I
>> >> >> > need
>> >> >> > for
>> >> >> > custom object within my folder array. I want to be able to set
>> >> >> > the
>> >> >> > date
>> >> >> > properties, to & from properties, read and unread properties, and
>> >> >> > a
>> >> >> > few
>> >> >> > other
>> >> >> > properties. When I create the _MailItem object I cannot gain
>> >> >> > access
>> >> >> > to
>> >> >> > a
>> >> >> > few
>> >> >> > of the properties without performing ugly procedures - does
>> >> >> > anybody
>> >> >> > have
>> >> >> > any
>> >> >> > suggestions?
>> >> >> >
>> >> >> > I have a method that will work but it is really ugly and I want
>> >> >> > to
>> >> >> > make
>> >> >> > this
>> >> >> > a little more robust. Any suggestions would be greatly
>> >> >> > appreciated.
>> >> >> >
>> >> >> > Thanks,
>> >> >> > Tom -
>> >> >> >
>> >> >>
>> >> >>
>> >> >>
>> >>
>> >>
>> >>
>>
>>
>>


Re: Custom _MailItem for Custom Store
Tom at GSD 2/16/2007 6:31:05 PM
Okay - that appeared to work. Thank you very much.

I had to set the icon index after the message was saved.

I have I few other hurdles to come such as setting the proper received time
and a few other items - but for the most part this was the major hurdle.

Thank you very much for you help.



"Dmitry Streblechenko" wrote:

[Quoted Text]
> Setting the sender related properties will have absolutely no effect on the
> sent/unsent state. It is controlled by the MSGFLAG_UNSENT bit in
> PR_MESSAGE_FLAGS. The bit can be modified only before the message is saved
> for the every first time. As long as you are using OOM, you won't be able to
> modify PR_MESSAGE_FLAGS through the MAPIOBJECT property because
> MailItem.Save will reset the flag when Save is called for the very first
> time.
> One possible workaround is to create a post item ("IPM.Post", it is created
> in the sent state), then reset the MessageClass property back to "IPM.Note"
> and delete the PR_ICON_INDEX property -
> http://www.dimastr.com/redemption/faq.htm#8
>
> Dmitry Streblechenko (MVP)
> http://www.dimastr.com/
> OutlookSpy - Outlook, CDO
> and MAPI Developer Tool
>
> "Tom at GSD" <TomatGSD[ at ]discussions.microsoft.com> wrote in message
> news:C1E4D26A-48CE-4D7F-B78C-9E053FBA2C71[ at ]microsoft.com...
> > Thanks for your reply.
> >
> > I was at one time saving the _MailItem and I put the call back in my
> > code -
> > but the save does not seem to help as far as setting the sent parameters.
> > In
> > other words I am still not able to setup the _MailItem to get it to look
> > like
> > it already has been sent. What MAPI properties will cause the _MailItem to
> > look as if it has been sent?
> >
> >
> > "Dmitry Streblechenko" wrote:
> >
> >> Save the item (spCustomItem->Save()) before moving it.
> >>
> >> Dmitry Streblechenko (MVP)
> >> http://www.dimastr.com/
> >> OutlookSpy - Outlook, CDO
> >> and MAPI Developer Tool
> >>
> >> "Tom at GSD" <TomatGSD[ at ]discussions.microsoft.com> wrote in message
> >> news:99B8E40F-4708-4DAB-AAB1-E39B9408677C[ at ]microsoft.com...
> >> > This is the code I am usiing through MAPI. I cut and pasted some of my
> >> > code.
> >> >
> >> > void CreateCustomMailItem()
> >> > {
> >> > // Create new mail item
> >> > CComQIPtr<Outlook::_MailItem> spCustomItem =
> >> > m_spApplication->CreateItem(Outlook::olMailItem);
> >> >
> >> > // Get message component
> >> > IUnknownPtr pUnk = spCustomItem->GetMAPIOBJECT();
> >> > CComQIPtr<IMessage, &IID_IMessage> spMessage(pUnk);
> >> >
> >> > // Set MAPI property (I hard coded a MAPI property for this example - I
> >> > have tried many)
> >> > SetProperty(spMessage, _T("blah[ at ]blah.com") ;
> >> >
> >> > // Move item to custom folder
> >> > spCustomItem->Move(m_spCustomEventFolder);
> >> > }
> >> >
> >> > HRESULT SetProperty(CComQIPtr<IMessage, &IID_IMessage> spMessage,
> >> > LPCTSTR
> >> > szValue)
> >> > {
> >> > HRESULT hr;
> >> > MAPINAMEID NamedProp;
> >> > NamedProp.ulKind = MNID_STRING;
> >> > MAPINAMEID* pNamedProp = &NamedProp;
> >> > LPSPropTagArray lpTags = 0;
> >> > SPropValue prop;
> >> > char szVal[500] = {NULL};
> >> >
> >> > #ifdef _UNICODE
> >> > char* pAnsiData = NULL;
> >> > UnicodeToAnsi(szValue, &pAnsiData);
> >> > strcpy(szVal, pAnsiData);
> >> > CoTaskMemFree(pAnsiData);
> >> > #else
> >> > strcpy(szVal, szValue);
> >> > #endif
> >> > // tried numerous properties
> >> > prop.ulPropTag =
> >> > PROP_TAG(PT_STRING8,PROP_ID(PR_SENDER_EMAIL_ADDRESS_A));
> >> > prop.Value.lpszA = (LPSTR)szVal;
> >> >
> >> > // Return S_OK all the time - but the values never change
> >> > hr = HrSetOneProp((LPMAPIPROP)(IUnknown*)spMessage, &prop );
> >> > MAPIFreeBuffer(lpTags);
> >> >
> >> > return hr;
> >> > }
> >> >
> >> >
> >> >
> >> >
> >> >
> >> >
> >> > "Dmitry Streblechenko" wrote:
> >> >
> >> >> Sender properies are not settable in the Outlook Obejct Model.
> >> >> You really need to show your code.
> >> >>
> >> >> Dmitry Streblechenko (MVP)
> >> >> http://www.dimastr.com/
> >> >> OutlookSpy - Outlook, CDO
> >> >> and MAPI Developer Tool
> >> >>
> >> >> "Tom at GSD" <TomatGSD[ at ]discussions.microsoft.com> wrote in message
> >> >> news:91EA64D3-D394-4D9C-9D21-87DCC457EBDE[ at ]microsoft.com...
> >> >> >I added a PST file that will store my custom items.
> >> >> >
> >> >> > I have created a _MailItem and I cannot set the date or any of the
> >> >> > email
> >> >> > address properties (sender and recipient). It seems like most of the
> >> >> > properties are not accessible until I send the message.
> >> >> >
> >> >> > I am creating a mail item and moving it to my custom folder. I want
> >> >> > to
> >> >> > be
> >> >> > able to set all properties (through MAPI or the Outlook classes) at
> >> >> > any
> >> >> > time.
> >> >> > When I try to set properties through MAPI my functionality returns a
> >> >> > success
> >> >> > (S_OK) - but the properties are never set. Am I missing something?
> >> >> >
> >> >> > BTW - the book you recommended is excellent. (Inside MAPI)
> >> >> >
> >> >> >
> >> >> >
> >> >> > "Dmitry Streblechenko" wrote:
> >> >> >
> >> >> >> Do you mean you wrote a custom MAPI store provider or that you
> >> >> >> added a
> >> >> >> PST
> >> >> >> store where you store your custom items?
> >> >> >> What prevents you from creating your own class that references
> >> >> >> MailItem
> >> >> >> internally and exposes your custom properties?
> >> >> >>
> >> >> >> Dmitry Streblechenko (MVP)
> >> >> >> http://www.dimastr.com/
> >> >> >> OutlookSpy - Outlook, CDO
> >> >> >> and MAPI Developer Tool
> >> >> >>
> >> >> >> "Tom at GSD" <TomatGSD[ at ]discussions.microsoft.com> wrote in message
> >> >> >> news:248A2DE5-CA0D-426E-A3D8-0D4F5B59C4CA[ at ]microsoft.com...
> >> >> >> > Hi,
> >> >> >> >
> >> >> >> > I have created an ATL C++ Outlook plug-in for Outlook 2003.
> >> >> >> >
> >> >> >> > I would like to create a custom _MailItem object; that I can
> >> >> >> > control
> >> >> >> > all
> >> >> >> > of
> >> >> >> > the properties at any time. Is this possible?
> >> >> >> >
> >> >> >> > I have created my own store with custom folders for custom
> >> >> >> > events.
> >> >> >> > It
> >> >> >> > so
> >> >> >> > happens that the _MailItem object has all of the properties that
> >> >> >> > I
> >> >> >> > need
> >> >> >> > for
> >> >> >> > custom object within my folder array. I want to be able to set
> >> >> >> > the
> >> >> >> > date
> >> >> >> > properties, to & from properties, read and unread properties, and
> >> >> >> > a
> >> >> >> > few
> >> >> >> > other
> >> >> >> > properties. When I create the _MailItem object I cannot gain
> >> >> >> > access
> >> >> >> > to
> >> >> >> > a
> >> >> >> > few
> >> >> >> > of the properties without performing ugly procedures - does
> >> >> >> > anybody
> >> >> >> > have
> >> >> >> > any
> >> >> >> > suggestions?
> >> >> >> >
> >> >> >> > I have a method that will work but it is really ugly and I want
> >> >> >> > to
> >> >> >> > make
> >> >> >> > this
> >> >> >> > a little more robust. Any suggestions would be greatly
> >> >> >> > appreciated.
> >> >> >> >
> >> >> >> > Thanks,
> >> >> >> > Tom -
> >> >> >> >
> >> >> >>
> >> >> >>
> >> >> >>
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>
>
>
>

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net