Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1056
  • Last Modified:

Look up e-mail recipients from Outlook address book

Here is what I need to be able to do.
We use Outlook 98 across the board around here.  If a user is composing an e-mail message and the recipient is something like 'Joe Blow', they can usually just write "Blow, J" or something like that and Outlook will resolve the rest.  It looks up the contact in the global address book and if there is only one match, it replaces "Blow, J" with that contact.  If there is more than one match it prompts the user to pick one.

In my app users can click a button to create a new e-mail message, with the body populated with info from the current record.  I have built in something that will also populate the 'To' field with a list of contacts.  This list is maintained by the users on a diferent form.  Each contact is just a name in plain text and optionally an e-mail address, but in most cases this is not required since it is always an internal contact.  What I do is create a new MAPI.Recipient, assign the e-mail address if applicable, assign its name accordingly, and then call MAPI.Recipient.Resolve to have it resolve to a contact on the outlook message.

What I would like to do is have the resolution happen on the other form where the list is maintained.  i.e., a user enters all or part of a contact name into my text box, clicks OK, and then it would resolve to the correct contact.  I would need to store the full name and e-mail address.  There would be no change to the way my e-mails are sent, it would still just have to take the plain text name and e-mail and assign it to a MAPI.Recipient.  The difference is that the user is able to check if the contact is valid or not when they first save that text.

In other words, I have a (full or partial) name, and I want a proper contact name and e-mail address from the global address book.

I hope this makes sense.  How can it be accomplished?

Thanks.

0
pteehan
Asked:
pteehan
  • 5
  • 3
1 Solution
 
Dang123Commented:
0
 
pteehanAuthor Commented:
Well, that's a good start...but it doesn't really do what I need, which is basically a function to look up a name query.  Partial name goes in, full name and e-mail address come out.  And sadly I have no time to figure it out for myself, hence the 500 points :)

Also I am hesitant to get into specific application code in case the client changes (at the very least to a new version of Outlook, which might happen soon).  The code I have in place now uses the MAPI interface and ideally I could use that if possible (though if there is no other option we could at least look at it).

I would think the MAPI.Recipient.Resolve function must do what I need somehow.  I just don't know how to use it properly.  

0
 
Dang123Commented:
Perhaps this is what you want. It is a small form that resolves a single name against the Outlook address book. You should be able to something similar on your second form, looping through the names, and save the information as you need.



In a new project add a referenct to Microsoft Outlook Object Library
On the form, add a text box and a command button.
Paste this code into the form.

'----------------------------------------------------
Private Sub Command1_Click()
    Dim OutlookApp As Outlook.Application
    Dim MailItem As Outlook.MailItem
    Dim Recipient As Outlook.Recipient
   
    Set OutlookApp = New Outlook.Application
    Set MailItem = OutlookApp.CreateItem(0)
    Set Recipient = MailItem.Recipients.Add(Text1.Text)
    If Recipient.Resolve Then
        Text1.Text = Recipient.Name
    Else
        MsgBox "There is an invalid recipient"
    End If
   
    Set Recipient = Nothing
    Set MailItem = Nothing
    Set OutlookApp = Nothing
End Sub

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
pteehanAuthor Commented:
Great!  Thanks.  Getting very close now.  I could probably use this.

THe only problem is that it is likely to fail a lot (there are a LOT of people at my company and thus a lot of ambiguous names) and there isn't really much they can do.  For example, if they enter John Smith it will always fail, unless I can get them to look up the e-mail address, but that will make it more difficult to use.

When you try and send a message to an ambiguous user in Outlook it pops up a dialog box with a list of possible matches, and it resolves to the one you pick.   Is it possible to launch this dialog if resolve fails and catch the name that the user picks?

0
 
Dang123Commented:
I'm having trouble finding something useful to put in the else for a failed resolve. I'll keep looking though!

Dang123

0
 
pteehanAuthor Commented:
I did some research into the CDO object reference on MSDN and was able to find an example that I could adapt.  I sidestepped the problem of failing resolves by focing them to choose a name from the original address book.  Here is the code for anyone who happens upon this page:

Function Session_AddressBook() As MAPI.Recipient
    On Error GoTo err_Session_AddressBook

    If objSession Is Nothing Then
        'Session_AddressBook = "LOOKUP FAILED"
       ' MsgBox "Must first create MAPI session and logon"
        Exit Function
    End If
    Set objRecipColl = objSession.AddressBook( _
                       Title:="Select Contact", _
                       oneAddress:=True, _
                       forceResolution:=True, _
                       recipLists:=1, _
                       toLabel:="&Recipient") ' appears on button
    ' Note: first parameter ("recipients") not used in this call
    ' recipients:=objInitRecipColl initializes recipients for dialog
'    MsgBox "Name of first recipient = " & objRecipColl.Item(1).Name
    Set Session_AddressBook = objRecipColl.item(1)
    Exit Function

err_Session_AddressBook:
    If (Err = 91) Then ' MAPI dlg-related function that sets an object
        'MsgBox "No recipients selected"
    Else
       ' MsgBox "Unrecoverable Error:" & Err
    End If
    Exit Function
End Function

Dang I appreciate your help even though I eventually found the answer myself.  I do want to reward your efforts but I am reluctant to let go of my 500 points! :)  What should I do.
0
 
Dang123Commented:
pteehan,
    Nice solution, glad you got your problem worked through. Sorry I couldn't provide more help, something with a higher priority came in a few days later from my boss; you know how that goes.

BTW: You could drop the point value to what ever you feel is appropriate.

Dang123

0
 
Dang123Commented:
pteehan,
    Thanks!   : )
Dang123
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now