HOWTO: Creating a One-Off Address

Last reviewed: June 18, 1997
Article ID: Q170319
The information in this article applies to:
  • Extended Messaging Application Programming Interface (MAPI), version 1.0

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

        // Allocate memory for new SRowSet structure.
        hRes = MAPIAllocateBuffer(CbNewSRowSet(1),(LPVOID*) &pAdrList)

        // If memory allocation fails, quit.
        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 memory allocation fails, quit.
        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.
        pAdrList->aEntries[0].cValues    = 5;  // How many properties
                                               // per recipient

        // Set the SPropValue members == the desired values.
        pAdrList->aEntries[0].rgPropVals[NAME].ulPropTag = PR_DISPLAY_NAME;
        pAdrList->aEntries[0].rgPropVals[NAME].lpszA =  "<Display Name>";

        pAdrList->aEntries[0].rgPropVals[ADDR].ulPropTag = PR_ADDRTYPE;
        pAdrList->aEntries[0].rgPropVals[ADDR].lpszA =  "SMTP";

        pAdrList->aEntries[0].rgPropVals[EMAIL].ulPropTag=PR_EMAIL_ADDRESS;
        pAdrList->aEntries[0].rgPropVals[EMAIL].lpszA = "<email address>";

        pAdrList->aEntries[0].rgPropVals[RECIP].ulPropTag=R_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 the call to CreateOneOff fails, quit.
        if ( FAILED ( hRes ) )
            goto Quit;

        // Attempt to resolve the new address list. If the attempt fails,
        // quit.
        if ( FAILED ( hRes = m_pAddrBook -> ResolveName ( 0L,
                                                          0L,
                                                          NULL,
                                                          pAdrList ) ) )
            goto Quit;

        // If everything goes right, add the new recipient to the message
        // object passed into us.
        hRes = pMsg->ModifyRecipients(MODRECIP_ADD,pAdrList);

    Quit:
        // Always release any newly created objects and allocated memory.
        FreePadrlist(pAdrList);

        return hRes;
    }

 

	
	


Keywords : EMAPI kbcode MAPIIAB
Version : WINDOWS:1.0
Platform : WINDOWS
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 18, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.