How to change recipients of a received message?

R

ryotyankou

My is ATL/VC2005. OnNewEmail to dispatch the event.
While OnNewEmail function were invoked, I tried the two methods:
1. MailItem->PutTo("(e-mail address removed);[email protected]");
2. Get IMessage interface, then call SetProps() function with Tag
PR_DISPLAY_TO_A, return value's S_OK. But when i open the message, nothing
were changed.
What should i do then?
 
R

ryotyankou via OfficeKB.com

And i tried the IMessage::ModifyRecipients(XXX_ADD), it still couldn't work.
And i modified the message header's "to:" field, it seems that no effect to
the message itself at all. Could someone help?
 
D

Dmitry Streblechenko

PR_DISPLAY_TO is not settable.
NewMail event (unlike NewMailEx) does not pass the new message as a
parameter. How do you retrieve the new message?
Do you save the message?

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

ryotyankou via OfficeKB.com

Not NewMailEx(BSTR xxx), what i processed is Outlook::ItemsEvents OnItemAdd
(LPDISPATCH).
With the income MailItem, How to add some other recipients to it? I tried the
following code, but couldn't work:
IUnknownPtr pUnkSession = MailItem->GetSession()->GetMAPIOBJECT();
if(pUnkSession == NULL)
return E_FAIL;

IUnknownPtr pUnkMsg = MailItem->GetMAPIOBJECT();
if(pUnkMsg == NULL)
return E_FAIL;

IMAPISession * pSession;
if(FAILED(pUnkSession->QueryInterface(IID_IMAPISession, (void**)&pSession)))
{
return E_FAIL;
}

IMessage *pMessage = NULL;
if(FAILED(pUnkMsg->QueryInterface(IID_IMessage, (void**)&pMessage)))
{
pSession->Release();
return E_FAIL;
}

//test only
int nBufSize = CbNewADRLIST(1);
LPADRLIST pAddressList=NULL;
MAPIAllocateBuffer(nBufSize,(LPVOID FAR*)&pAddressList);
memset(pAddressList,0,nBufSize);

const int nProperties=2;
pAddressList->cEntries=1;

pAddressList->aEntries[0].ulReserved1=0;
pAddressList->aEntries[0].cValues=nProperties;

MAPIAllocateBuffer(sizeof(SPropValue)*nProperties,(LPVOID FAR*)&pAddressList-
aEntries[0].rgPropVals);
memset(pAddressList->aEntries[0].rgPropVals, 0, sizeof(SPropValue)
*nProperties);

pAddressList->aEntries[0].rgPropVals[0].ulPropTag=PR_RECIPIENT_TYPE;
pAddressList->aEntries[0].rgPropVals[0].Value.ul=MAPI_TO;

CString temp("(e-mail address removed)");
pAddressList->aEntries[0].rgPropVals[1].ulPropTag=PR_DISPLAY_NAME;
pAddressList->aEntries[0].rgPropVals[1].Value.lpszA=(LPSTR)temp.GetString();

// IAddrBook * pAddrBook = NULL;
// if(FAILED(pSession->OpenAddressBook(0, NULL, AB_NO_DIALOG, &pAddrBook)))
// {
// pSession->Release();
// pMessage->Release();
// FreePadrlist(pAddressList);
// return E_FAIL;
// }

// if(FAILED(pAddrBook->ResolveName(0, cm_nMAPICode, NULL, pAddressList)))
// {
// pSession->Release();
// pMessage->Release();
// FreePadrlist(pAddressList);
// pAddrBook->Release();
// return E_FAIL;
// }

if(FAILED(pMessage->ModifyRecipients(MODRECIP_ADD, pAddressList)))
{
pSession->Release();
pMessage->Release();
FreePadrlist(pAddressList);
// pAddrBook->Release();
return E_FAIL;
}

FreePadrlist(pAddressList);
pMessage->Release();
// pAddrBook->Release();
pSession->Release();

Dmitry said:
PR_DISPLAY_TO is not settable.
NewMail event (unlike NewMailEx) does not pass the new message as a
parameter. How do you retrieve the new message?
Do you save the message?
My is ATL/VC2005. OnNewEmail to dispatch the event.
While OnNewEmail function were invoked, I tried the two methods:
[quoted text clipped - 3 lines]
were changed.
What should i do then?
 
R

ryotyankou via OfficeKB.com

Hi, Dmitry, I checked my code and found that my process is not cogitate(Use
OnItemAdd, not OnNewMailEx), if the MailItem's encrypted, the add-in will do
nothing. Can i convert the entryid(OnNewEmailEx) to MailItem? How could i get
IMessage from entryid? Thanks a lot.

Dmitry said:
PR_DISPLAY_TO is not settable.
NewMail event (unlike NewMailEx) does not pass the new message as a
parameter. How do you retrieve the new message?
Do you save the message?
My is ATL/VC2005. OnNewEmail to dispatch the event.
While OnNewEmail function were invoked, I tried the two methods:
[quoted text clipped - 3 lines]
were changed.
What should i do then?
 
R

ryotyankou via OfficeKB.com

void __stdcall CPlug1::OnNewMailEx(BSTR EntryId)
{
Outlook::_NameSpacePtr m_NameSpacePtr = m_spApp->ActiveExplorer()-
GetSession();
if(m_NameSpacePtr == NULL)
{
return;
}
Outlook::_MailItemPtr MailItem = m_NameSpacePtr->GetItemFromID(_bstr_t
(EntryId));
//do other things
}
The code can work with most of the case but encrypted MailItem, again, What
should i do then?
PR_DISPLAY_TO is not settable.
NewMail event (unlike NewMailEx) does not pass the new message as a
[quoted text clipped - 6 lines]
 
D

Dmitry Streblechenko

You never save the message

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
ryotyankou via OfficeKB.com said:
Not NewMailEx(BSTR xxx), what i processed is Outlook::ItemsEvents
OnItemAdd
(LPDISPATCH).
With the income MailItem, How to add some other recipients to it? I tried
the
following code, but couldn't work:
IUnknownPtr pUnkSession = MailItem->GetSession()->GetMAPIOBJECT();
if(pUnkSession == NULL)
return E_FAIL;

IUnknownPtr pUnkMsg = MailItem->GetMAPIOBJECT();
if(pUnkMsg == NULL)
return E_FAIL;

IMAPISession * pSession;
if(FAILED(pUnkSession->QueryInterface(IID_IMAPISession,
(void**)&pSession)))
{
return E_FAIL;
}

IMessage *pMessage = NULL;
if(FAILED(pUnkMsg->QueryInterface(IID_IMessage, (void**)&pMessage)))
{
pSession->Release();
return E_FAIL;
}

//test only
int nBufSize = CbNewADRLIST(1);
LPADRLIST pAddressList=NULL;
MAPIAllocateBuffer(nBufSize,(LPVOID FAR*)&pAddressList);
memset(pAddressList,0,nBufSize);

const int nProperties=2;
pAddressList->cEntries=1;

pAddressList->aEntries[0].ulReserved1=0;
pAddressList->aEntries[0].cValues=nProperties;

MAPIAllocateBuffer(sizeof(SPropValue)*nProperties,(LPVOID
FAR*)&pAddressList-
aEntries[0].rgPropVals);
memset(pAddressList->aEntries[0].rgPropVals, 0, sizeof(SPropValue)
*nProperties);

pAddressList->aEntries[0].rgPropVals[0].ulPropTag=PR_RECIPIENT_TYPE;
pAddressList->aEntries[0].rgPropVals[0].Value.ul=MAPI_TO;

CString temp("(e-mail address removed)");
pAddressList->aEntries[0].rgPropVals[1].ulPropTag=PR_DISPLAY_NAME;
pAddressList->aEntries[0].rgPropVals[1].Value.lpszA=(LPSTR)temp.GetString();

// IAddrBook * pAddrBook = NULL;
// if(FAILED(pSession->OpenAddressBook(0, NULL, AB_NO_DIALOG,
&pAddrBook)))
// {
// pSession->Release();
// pMessage->Release();
// FreePadrlist(pAddressList);
// return E_FAIL;
// }

// if(FAILED(pAddrBook->ResolveName(0, cm_nMAPICode, NULL, pAddressList)))
// {
// pSession->Release();
// pMessage->Release();
// FreePadrlist(pAddressList);
// pAddrBook->Release();
// return E_FAIL;
// }

if(FAILED(pMessage->ModifyRecipients(MODRECIP_ADD, pAddressList)))
{
pSession->Release();
pMessage->Release();
FreePadrlist(pAddressList);
// pAddrBook->Release();
return E_FAIL;
}

FreePadrlist(pAddressList);
pMessage->Release();
// pAddrBook->Release();
pSession->Release();

Dmitry said:
PR_DISPLAY_TO is not settable.
NewMail event (unlike NewMailEx) does not pass the new message as a
parameter. How do you retrieve the new message?
Do you save the message?
My is ATL/VC2005. OnNewEmail to dispatch the event.
While OnNewEmail function were invoked, I tried the two methods:
[quoted text clipped - 3 lines]
were changed.
What should i do then?
 
D

Dmitry Streblechenko

So what happens when you process an encrypted message?

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
ryotyankou via OfficeKB.com said:
void __stdcall CPlug1::OnNewMailEx(BSTR EntryId)
{
Outlook::_NameSpacePtr m_NameSpacePtr = m_spApp->ActiveExplorer()-
GetSession();
if(m_NameSpacePtr == NULL)
{
return;
}
Outlook::_MailItemPtr MailItem = m_NameSpacePtr->GetItemFromID(_bstr_t
(EntryId));
//do other things
}
The code can work with most of the case but encrypted MailItem, again,
What
should i do then?
PR_DISPLAY_TO is not settable.
NewMail event (unlike NewMailEx) does not pass the new message as a
[quoted text clipped - 6 lines]
were changed.
What should i do then?
 
R

ryotyankou via OfficeKB.com

Outlook::_MailItemPtr MailItem = m_NameSpacePtr->GetItemFromID(_bstr_t
(EntryId));
If the message's encrypted, the MailItem is NULL, otherwise, it is ok.

Dmitry said:
So what happens when you process an encrypted message?
void __stdcall CPlug1::OnNewMailEx(BSTR EntryId)
{
[quoted text clipped - 17 lines]
 
D

Dmitry Streblechenko

Are you sure you specify the right entry id?
Do you get an error? I don't think GetItemFromID can ever return null rather
than raise an exception.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
ryotyankou via OfficeKB.com said:
Outlook::_MailItemPtr MailItem = m_NameSpacePtr->GetItemFromID(_bstr_t
(EntryId));
If the message's encrypted, the MailItem is NULL, otherwise, it is ok.

Dmitry said:
So what happens when you process an encrypted message?
void __stdcall CPlug1::OnNewMailEx(BSTR EntryId)
{
[quoted text clipped - 17 lines]
were changed.
What should i do then?
 

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