Microsoft KB Archive/170319: Difference between revisions
m (Text replacement - "<" to "<") |
m (Text replacement - ">" to ">") |
||
Line 90: | Line 90: | ||
hRes = MAPIAllocateBuffer( | hRes = MAPIAllocateBuffer( | ||
NUM_RECIP_PROPS * sizeof(SPropValue), | NUM_RECIP_PROPS * sizeof(SPropValue), | ||
(LPVOID*) &(pAdrList- | (LPVOID*) &(pAdrList->aEntries[0].rgPropVals)); | ||
if (FAILED(hRes)) goto Quit; | if (FAILED(hRes)) goto Quit; | ||
// Zero out allocated memory. | // Zero out allocated memory. | ||
ZeroMemory(pAdrList - | ZeroMemory(pAdrList -> aEntries[0].rgPropVals, | ||
NUM_RECIP_PROPS * sizeof(SPropValue) ); | NUM_RECIP_PROPS * sizeof(SPropValue) ); | ||
Line 100: | Line 100: | ||
// recipients and how many properties will be set on each // recipient. | // recipients and how many properties will be set on each // recipient. | ||
pAdrList- | pAdrList->cEntries = 1; // How many recipients. | ||
// How many properties per recipient | // How many properties per recipient | ||
pAdrList- | pAdrList->aEntries[0].cValues = NUM_RECIP_PROPS; | ||
// Set the SPropValue members == the desired values. | // Set the SPropValue members == the desired values. | ||
pAdrList- | pAdrList->aEntries[0].rgPropVals[NAME].ulPropTag = PR_DISPLAY_NAME; | ||
pAdrList- | pAdrList->aEntries[0].rgPropVals[NAME].Value.lpszA = | ||
"<Display Name | "<Display Name>"; | ||
pAdrList- | pAdrList->aEntries[0].rgPropVals[ADDR].ulPropTag = | ||
PR_ADDRTYPE; | PR_ADDRTYPE; | ||
pAdrList- | pAdrList->aEntries[0].rgPropVals[ADDR].Value.lpszA = | ||
"SMTP"; | "SMTP"; | ||
pAdrList- | pAdrList->aEntries[0].rgPropVals[EMAIL].ulPropTag = | ||
PR_EMAIL_ADDRESS; | PR_EMAIL_ADDRESS; | ||
pAdrList- | pAdrList->aEntries[0].rgPropVals[EMAIL].Value.lpszA = | ||
"<email address | "<email address>"; | ||
pAdrList- | pAdrList->aEntries[0].rgPropVals[RECIP].ulPropTag = | ||
PR_RECIPIENT_TYPE; | PR_RECIPIENT_TYPE; | ||
pAdrList- | pAdrList->aEntries[0].rgPropVals[RECIP].Value.l = | ||
MAPI_TO; | MAPI_TO; | ||
pAdrList- | pAdrList->aEntries[0].rgPropVals[EID].ulPropTag = | ||
PR_ENTRYID; | PR_ENTRYID; | ||
// Create the One-off address and get an EID for it. | // Create the One-off address and get an EID for it. | ||
hRes = m_pAddrBook- | hRes = m_pAddrBook->CreateOneOff( | ||
pAdrList- | pAdrList-> aEntries[0].rgPropVals[NAME].Value.lpszA, | ||
pAdrList- | pAdrList-> aEntries[0].rgPropVals[ADDR].Value.lpszA, | ||
pAdrList- | pAdrList-> aEntries[0].rgPropVals[EMAIL].Value.lpszA, | ||
0, | 0, | ||
&pAdrList- | &pAdrList->aEntries[0].rgPropVals[EID].Value.bin.cb, | ||
(LPENTRYID*) | (LPENTRYID*) | ||
(&pAdrList- | (&pAdrList->aEntries[0].rgPropVals[EID].Value.bin.lpb)); | ||
if (FAILED(hRes)) goto Quit; | if (FAILED(hRes)) goto Quit; | ||
hRes = m_pAddrBook- | hRes = m_pAddrBook->ResolveName( | ||
0L, | 0L, | ||
0L, | 0L, | ||
Line 147: | Line 147: | ||
// If everything goes right, add the new recipient to the | // If everything goes right, add the new recipient to the | ||
// message object passed into us. | // message object passed into us. | ||
hRes = pMsg- | hRes = pMsg->ModifyRecipients(MODRECIP_ADD,pAdrList); | ||
if (FAILED(hRes)) goto Quit; | if (FAILED(hRes)) goto Quit; | ||
hRes = pMsg- | hRes = pMsg->SaveChanges(FORCE_SAVE); | ||
if (FAILED(hRes)) goto Quit; | if (FAILED(hRes)) goto Quit; | ||
Revision as of 20:31, 20 July 2020
Article ID: 170319
Article Last Modified on 8/18/2005
APPLIES TO
- Microsoft Messaging Application Programming Interface
This article was previously published under Q170319
SUMMARY
This article explains how to programmatically call the CreateOneOff method of the IAddrBook::IMAPIProp interface and attach the newly created address to an existing message object.
MORE INFORMATION
Most address book providers support the ability to create temporary e-mail addresses so that users can send mail to a one-time recipient or to recipients that do not appear in a read-only list or a Global Address List.
Messaging Application Programming Interface (MAPI) clients that want to facilitate this feature should follow these steps and use similar code to incorporate this feature. (NOTE: The following code segments assume an existing connection to a MAPI session exists):
HRESULT TestAddress(LPMESSAGE pMsg) { HRESULT hRes = S_OK; // Status code of MAPI calls LPADRLIST pAdrList = NULL; // ModifyRecips takes LPADRLIST enum {NAME, ADDR, EMAIL, RECIP, EID, NUM_RECIP_PROPS }; SizedSPropTagArray(NUM_RECIP_PROPS, sRecipProps) = { NUM_RECIP_PROPS, // number of columns (properties) { PR_DISPLAY_NAME, PR_ADDRTYPE, PR_EMAIL_ADDRESS, PR_RECIPIENT_TYPE, PR_ENTRYID } }; // Allocate memory for new SRowSet structure. hRes = MAPIAllocateBuffer(CbNewSRowSet(1), (LPVOID*) &pAdrList); if (FAILED(hRes)) goto Quit; // Zero out allocated memory. ZeroMemory(pAdrList, CbNewSRowSet(1)); // Allocate memory for SPropValue structure that indicates what // recipient properties will be set. NUM_RECIP_PROPS == 5. hRes = MAPIAllocateBuffer( NUM_RECIP_PROPS * sizeof(SPropValue), (LPVOID*) &(pAdrList->aEntries[0].rgPropVals)); if (FAILED(hRes)) goto Quit; // Zero out allocated memory. ZeroMemory(pAdrList -> aEntries[0].rgPropVals, NUM_RECIP_PROPS * sizeof(SPropValue) ); // Setup the One Time recipient by indicating how many // recipients and how many properties will be set on each // recipient. pAdrList->cEntries = 1; // How many recipients. // How many properties per recipient pAdrList->aEntries[0].cValues = NUM_RECIP_PROPS; // Set the SPropValue members == the desired values. pAdrList->aEntries[0].rgPropVals[NAME].ulPropTag = PR_DISPLAY_NAME; pAdrList->aEntries[0].rgPropVals[NAME].Value.lpszA = "<Display Name>"; pAdrList->aEntries[0].rgPropVals[ADDR].ulPropTag = PR_ADDRTYPE; pAdrList->aEntries[0].rgPropVals[ADDR].Value.lpszA = "SMTP"; pAdrList->aEntries[0].rgPropVals[EMAIL].ulPropTag = PR_EMAIL_ADDRESS; pAdrList->aEntries[0].rgPropVals[EMAIL].Value.lpszA = "<email address>"; pAdrList->aEntries[0].rgPropVals[RECIP].ulPropTag = PR_RECIPIENT_TYPE; pAdrList->aEntries[0].rgPropVals[RECIP].Value.l = MAPI_TO; pAdrList->aEntries[0].rgPropVals[EID].ulPropTag = PR_ENTRYID; // Create the One-off address and get an EID for it. hRes = m_pAddrBook->CreateOneOff( pAdrList-> aEntries[0].rgPropVals[NAME].Value.lpszA, pAdrList-> aEntries[0].rgPropVals[ADDR].Value.lpszA, pAdrList-> aEntries[0].rgPropVals[EMAIL].Value.lpszA, 0, &pAdrList->aEntries[0].rgPropVals[EID].Value.bin.cb, (LPENTRYID*) (&pAdrList->aEntries[0].rgPropVals[EID].Value.bin.lpb)); if (FAILED(hRes)) goto Quit; hRes = m_pAddrBook->ResolveName( 0L, 0L, NULL, pAdrList ); if (FAILED(hRes)) goto Quit; // If everything goes right, add the new recipient to the // message object passed into us. hRes = pMsg->ModifyRecipients(MODRECIP_ADD,pAdrList); if (FAILED(hRes)) goto Quit; hRes = pMsg->SaveChanges(FORCE_SAVE); if (FAILED(hRes)) goto Quit; Quit: // Always release any newly created objects and // allocated memory. FreePadrlist(pAdrList); return hRes; }
Keywords: kbhowto kbmsg kbcode KB170319