Custom _MailItem for Custom Store

T

Tom at GSD

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

Dmitry Streblechenko

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
 
T

Tom at GSD

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

Dmitry Streblechenko

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
 
T

Tom at GSD

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::eek:lMailItem);

// 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("(e-mail address removed)") ;

// 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;
}
 
D

Dmitry Streblechenko

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 said:
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::eek:lMailItem);

// 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("(e-mail address removed)") ;

// 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 said:
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
 
T

Tom at GSD

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 said:
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 said:
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::eek:lMailItem);

// 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("(e-mail address removed)") ;

// 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 said:
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

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)



:

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

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

Dmitry Streblechenko

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 said:
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 said:
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 said:
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::eek:lMailItem);

// 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("(e-mail address removed)") ;

// 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;
}






:

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

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)



:

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

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

Tom at GSD

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 said:
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 said:
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 said:
Save the item (spCustomItem->Save()) before moving it.

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

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::eek:lMailItem);

// 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("(e-mail address removed)") ;

// 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;
}






:

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

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)



:

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

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 -
 

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