HRESULT AddRecipientW(LPMESSAGE lpMessage, ULONG ulRecipientType, LPWSTR szRecipientName){ HRESULT hRes = S_OK; LPADRLIST lpAdrList = NULL; // ModifyRecips takes LPADRLIST LPADRBOOK lpAddrBook = NULL; hRes = HrAllocAdrList(NUM_RECIP_PROPS, &lpAdrList); if (SUCCEEDED(hRes) && lpAdrList) { // Set up the recipient by indicating how many recipients // and how many properties will be set on each recipient. lpAdrList->cEntries = 1; // How many recipients. lpAdrList->aEntries[0].cValues = NUM_RECIP_PROPS; // How many properties per recipient lpAdrList->aEntries[0].rgPropVals[p_PR_DISPLAY_NAME_W].ulPropTag = PR_DISPLAY_NAME_W; lpAdrList->aEntries[0].rgPropVals[p_PR_RECIPIENT_TYPE].ulPropTag = PR_RECIPIENT_TYPE; lpAdrList->aEntries[0].rgPropVals[p_PR_DISPLAY_NAME_W].Value.lpszW = szRecipientName; lpAdrList->aEntries[0].rgPropVals[p_PR_RECIPIENT_TYPE].Value.l = ulRecipientType; // If everything goes right, add the new recipient to the message // object passed into us. hRes = lpMessage->ModifyRecipients(MODRECIP_ADD, lpAdrList); } if (lpAdrList) FreePadrlist(lpAdrList); if (lpAddrBook) lpAddrBook->Release(); return hRes; }
_Check_return_ HRESULT AddRecipient( _In_ LPMAPISESSION lpMAPISession, _In_ LPMESSAGE lpMessage, _In_z_ LPCTSTR szName, ULONG ulRecipientType) { HRESULT hRes = S_OK; LPADRLIST lpAdrList = NULL; // ModifyRecips takes LPADRLIST LPADRBOOK lpAddrBook = NULL; enum { NAME, RECIP, NUM_RECIP_PROPS }; if (!lpMessage || !lpMAPISession) return MAPI_E_INVALID_PARAMETER; EC_MAPI(lpMAPISession->OpenAddressBook( NULL, NULL, NULL, &lpAddrBook)); EC_MAPI(HrAllocAdrList(NUM_RECIP_PROPS, &lpAdrList)); if (lpAdrList) { // Setup the One Time recipient by indicating how many recipients // and how many properties will be set on each recipient. lpAdrList->cEntries = 1; // How many recipients. lpAdrList->aEntries[0].cValues = NUM_RECIP_PROPS; // How many properties per recipient // Set the SPropValue members == the desired values. lpAdrList->aEntries[0].rgPropVals[NAME].ulPropTag = PR_DISPLAY_NAME; lpAdrList->aEntries[0].rgPropVals[NAME].Value.LPSZ = (LPTSTR)szName; lpAdrList->aEntries[0].rgPropVals[RECIP].ulPropTag = PR_RECIPIENT_TYPE; lpAdrList->aEntries[0].rgPropVals[RECIP].Value.l = ulRecipientType; EC_MAPI(lpAddrBook->ResolveName( 0L, fMapiUnicode, NULL, lpAdrList)); // If everything goes right, add the new recipient to the message // object passed into us. EC_MAPI(lpMessage->ModifyRecipients(MODRECIP_ADD, lpAdrList)); EC_MAPI(lpMessage->SaveChanges(KEEP_OPEN_READWRITE)); } if (lpAdrList) FreePadrlist(lpAdrList); if (lpAddrBook) lpAddrBook->Release(); return hRes; } // AddRecipient
HRESULT AddRecipientA(LPMAPISESSION lpMAPISession, LPMESSAGE lpMessage, ULONG ulRecipientType, LPSTR szRecipientName) { HRESULT hRes = S_OK; LPADRLIST lpAdrList = NULL; // ModifyRecips takes LPADRLIST LPADRBOOK lpAddrBook = NULL; if (!lpMessage || !lpMAPISession) return MAPI_E_INVALID_PARAMETER; hRes = lpMAPISession->OpenAddressBook( NULL, NULL, NULL, &lpAddrBook); if (SUCCEEDED(hRes) && lpAddrBook) { hRes = HrAllocAdrList(NUM_RECIP_PROPS, &lpAdrList); if (SUCCEEDED(hRes) && lpAdrList) { // Set up the recipient by indicating how many recipients // and how many properties will be set on each recipient. lpAdrList->cEntries = 1; // How many recipients. lpAdrList->aEntries[0].cValues = NUM_RECIP_PROPS; // How many properties per recipient lpAdrList->aEntries[0].rgPropVals[p_PR_DISPLAY_NAME_W].ulPropTag = PR_DISPLAY_NAME_A; lpAdrList->aEntries[0].rgPropVals[p_PR_RECIPIENT_TYPE].ulPropTag = PR_RECIPIENT_TYPE; lpAdrList->aEntries[0].rgPropVals[p_PR_DISPLAY_NAME_W].Value.lpszA = szRecipientName; lpAdrList->aEntries[0].rgPropVals[p_PR_RECIPIENT_TYPE].Value.l = ulRecipientType; hRes = lpAddrBook->ResolveName( 0L, MAPI_UNICODE, NULL, lpAdrList); if (SUCCEEDED(hRes)) { // If everything goes right, add the new recipient to the message // object passed into us. hRes = lpMessage->ModifyRecipients(MODRECIP_ADD, lpAdrList); } } } if (lpAdrList) FreePadrlist(lpAdrList); if (lpAddrBook) lpAddrBook->Release(); return hRes; }
_Check_return_ HRESULT AddOneOffAddress( _In_ LPMAPISESSION lpMAPISession, _In_ LPMESSAGE lpMessage, _In_z_ LPCTSTR szDisplayName, _In_z_ LPCTSTR szAddrType, _In_z_ LPCTSTR szEmailAddress, ULONG ulRecipientType) { HRESULT hRes = S_OK; LPADRLIST lpAdrList = NULL; // ModifyRecips takes LPADRLIST LPADRBOOK lpAddrBook = NULL; LPENTRYID lpEID = NULL; enum { NAME, ADDR, EMAIL, RECIP, EID, NUM_RECIP_PROPS }; if (!lpMessage || !lpMAPISession) return MAPI_E_INVALID_PARAMETER; EC_MAPI(lpMAPISession->OpenAddressBook( NULL, NULL, NULL, &lpAddrBook)); EC_MAPI(HrAllocAdrList(NUM_RECIP_PROPS, &lpAdrList)); // Setup the One Time recipient by indicating how many recipients // and how many properties will be set on each recipient. if (SUCCEEDED(hRes) && lpAdrList) { lpAdrList->cEntries = 1; // How many recipients. lpAdrList->aEntries[0].cValues = NUM_RECIP_PROPS; // How many properties per recipient // Set the SPropValue members == the desired values. lpAdrList->aEntries[0].rgPropVals[NAME].ulPropTag = PR_DISPLAY_NAME; lpAdrList->aEntries[0].rgPropVals[NAME].Value.LPSZ = (LPTSTR)szDisplayName; lpAdrList->aEntries[0].rgPropVals[ADDR].ulPropTag = PR_ADDRTYPE; lpAdrList->aEntries[0].rgPropVals[ADDR].Value.LPSZ = (LPTSTR)szAddrType; lpAdrList->aEntries[0].rgPropVals[EMAIL].ulPropTag = PR_EMAIL_ADDRESS; lpAdrList->aEntries[0].rgPropVals[EMAIL].Value.LPSZ = (LPTSTR)szEmailAddress; lpAdrList->aEntries[0].rgPropVals[RECIP].ulPropTag = PR_RECIPIENT_TYPE; lpAdrList->aEntries[0].rgPropVals[RECIP].Value.l = ulRecipientType; lpAdrList->aEntries[0].rgPropVals[EID].ulPropTag = PR_ENTRYID; // Create the One-off address and get an EID for it. EC_MAPI(lpAddrBook->CreateOneOff( lpAdrList->aEntries[0].rgPropVals[NAME].Value.LPSZ, lpAdrList->aEntries[0].rgPropVals[ADDR].Value.LPSZ, lpAdrList->aEntries[0].rgPropVals[EMAIL].Value.LPSZ, fMapiUnicode, &lpAdrList->aEntries[0].rgPropVals[EID].Value.bin.cb, &lpEID)); lpAdrList->aEntries[0].rgPropVals[EID].Value.bin.lpb = (LPBYTE)lpEID; EC_MAPI(lpAddrBook->ResolveName( 0L, fMapiUnicode, NULL, lpAdrList)); // If everything goes right, add the new recipient to the message // object passed into us. EC_MAPI(lpMessage->ModifyRecipients(MODRECIP_ADD, lpAdrList)); EC_MAPI(lpMessage->SaveChanges(KEEP_OPEN_READWRITE)); } MAPIFreeBuffer(lpEID); if (lpAdrList) FreePadrlist(lpAdrList); if (lpAddrBook) lpAddrBook->Release(); return hRes; } // AddOneOffAddress