Title: to select a recipient from addressbook
Q:
How can I select a recipient from addressbook?
A:
Today I want to post a tip about copying of recipients from
default addressbook. For example, user must select a list of recipients
and you'll process this list in own code (to send a message to
these recipients or just import them into own database).
For this task you can use the MAPIAddress procedure from MAPI.
This procedure requires a handle of current session (which you'll
receive from MAPILogOn procedure), custom caption of dialog,
structure for recepient attributes and variable where you'll
receive a number of selected recipients.
If MSPIAddress returns SUCCESS_SUCCESS, this mean that user
closed a dialog and selected some recipients. After that you must
navigater by recipient structure (which you defined as parameter)
and process the each recipient.
For example:
var
lpRecip: TMapiRecipDesc;
intRecips: ULONG;
lpRecips: PMapiRecipDesc;
i: Integer;
begin
if (MAPIAddress(intMAPISession, 0, 'Select the recipients', 4, '', 0, lpRecip, 0, 0, @intRecips, lpRecips) = SUCCESS_SUCCESS) then
begin
for i := 0 to intRecips-1 do
yourListBox.Items.Add(PMapiRecipDesc(PChar(lpRecips) + i*SizeOf(TMapiRecipDesc))^.lpszAddress);
MAPIFreeBuffer(lpRecips)
end;
end;
I hope that this tip will help you and save some time. At
least when I wrote (in October 2000) this code for own GroupMail,
I spent a lot of time for correct work without errors:-)