Solved

Look up e-mail recipients from Outlook address book

Posted on 2003-11-19
9
1,045 Views
Last Modified: 2007-12-19
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
Comment
Question by:pteehan
  • 5
  • 3
9 Comments
 
LVL 9

Expert Comment

by:Dang123
ID: 9782688
0
 
LVL 2

Author Comment

by:pteehan
ID: 9782800
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
 
LVL 9

Accepted Solution

by:
Dang123 earned 250 total points
ID: 9787360
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
 
LVL 2

Author Comment

by:pteehan
ID: 9789378
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 9

Expert Comment

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

Dang123

0
 
LVL 2

Author Comment

by:pteehan
ID: 9850465
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
 
LVL 9

Expert Comment

by:Dang123
ID: 9850729
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
 
LVL 9

Expert Comment

by:Dang123
ID: 9857690
pteehan,
    Thanks!   : )
Dang123
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now