Microsoft KB Archive/280377

= How To Send Mail to a Hidden Recipient Using MAPI =

Article ID: 280377

Article Last Modified on 8/25/2005

-

APPLIES TO


 * Microsoft Messaging Application Programming Interface

-



This article was previously published under Q280377



SUMMARY
Some mailboxes in Microsoft Exchange may be hidden from the Global Address List (GAL). If you try to use MAPI to send an e-mail to a hidden mailbox using the Simple Mail Transfer Protocol (SMTP) address from your program, the action will fail because Exchange cannot resolve the name. However, you can use the Distinguished Name (DN) for the mailbox to send e-mail successfully.



MORE INFORMATION
To cause Exchange to resolve the DN for a hidden mailbox, you must create an address entry (ADRENTRY) structure with PR_DISPLAY_NAME set to an one-off address. The format for this is

Display Name [EX:/O=EXCH_ORGANIZATION/OU=FIRST ADMINISTRATIVE GROUP/CN=RECIPIENTS/CN=USERNAME]

After you set up an address entry with the one-off address, you can make a call to the IAddrBook::ResolveName method to resolve the address entry. After this is done, you can send e-mail to the hidden mailbox.

The following code shows how to do this: HRESULT AddressMessage(LPMAPISESSION lpSession, LPMESSAGE lpMessage, LPSTR pszRecip, long lRecipType) {   HRESULT hRes = S_OK; LPADRLIST lpAddrList = NULL; LPADRBOOK lpAddrBook = NULL; int cValues = 2;

int cb = CbNewADRLIST(1);

hRes = MAPIAllocateBuffer(cb, (LPVOID *)&lpAddrList); if (FAILED(hRes)) goto Cleanup;

ZeroMemory(lpAddrList, cb);

hRes = MAPIAllocateBuffer(       cValues * sizeof(SPropValue),         (LPVOID FAR *)&lpAddrList->aEntries[0].rgPropVals); if (FAILED(hRes)) goto Cleanup; // pszRecip = &quot;John Doe [EX:/O=EXCHANGE_ORG/OU=FIRST ADMINISTRATIVE GROUP/CN=RECIPIENTS/CN=USERNAME]&quot; lpAddrList->aEntries[0].rgPropVals[0].ulPropTag = PR_DISPLAY_NAME; lpAddrList->aEntries[0].rgPropVals[0].Value.LPSZ = pszRecip;

// lRecipType = MAPI_TO lpAddrList->aEntries[0].rgPropVals[1].ulPropTag = PR_RECIPIENT_TYPE; lpAddrList->aEntries[0].rgPropVals[1].Value.l = lRecipType; lpAddrList->aEntries[0].cValues = cValues; hRes = lpSession->OpenAddressBook(0, NULL, 0, &lpAddrBook); if (FAILED(hRes)) goto Cleanup;

lpAddrList->cEntries = 1;

hRes = lpAddrBook->ResolveName(0, 0, NULL, lpAddrList); if (FAILED(hRes)) goto Cleanup;

hRes = lpMessage->ModifyRecipients(MODRECIP_ADD,lpAddrList); if (FAILED(hRes)) goto Cleanup;

Cleanup: FreePadrlist(lpAddrList); if (lpAddrBook) lpAddrBook->Release; return hRes; }

