Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


July 2000

Showing Contacts' Email Addresses


RSS
Subscribe to Windows IT Pro | See More Exchange Server and Outlook Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

Download the Code Here

In the June 2000 Outlook VBA on Demand column, I showed you how to use VBA in Outlook 2000 to display, for a message in your Inbox folder, the sender's email address. In this installment, I show you how to build a small application that loops through any folder containing contacts and updates the items so that an open contact's (or folder view's) email fields display the Internet email address—not the name of the contact.

Outlook uses two separate properties—one for the address and one for a display name—for each of a contact's three email fields. In the contact item and the contacts folder view, you always see the display name. Depending on how you create the contact, the display name might default to the contact's FullName property. You might think that you can simply update the Email1DisplayName property with the value in the Email1Address property, but you can't. The Email1DisplayName property is read-only. The only way you can update it is to completely recreate the email address entry—and that is what this column's application does.

Create a new module in Outlook VBA (or use an existing module in which you've been creating macros), and add a new subroutine that uses the code you see in Listing 1. The subroutine uses the PickFolder method on the Namespace object to let the user select the folder to update; then, the subroutine returns the folder's collection of items as the colContacts object variable and returns the first item in the folder. Because Outlook 2000 contacts folders can contain distribution lists (DLs) as well as contacts, the Dim objItem As Object statement declares the object that represents an item in the folder as a generic Object, not as a ContactItem object. When working in a contacts folder, you should always declare the object variable that represents an individual item as a generic Object, then use the object variable's Class property to check the actual type as you loop through the items in the folder:

If objItem.Class = olContact Then

You could also use the TypeName() function, if you prefer. After you've ensured that the item is a ContactItem, you can access its properties and make your changes. To minimize the amount of work the procedure must perform, the subroutine checks to see whether the item's first address is an Internet (i.e., SMTP) address and whether the item's display name and address are different:

If .Email1AddressType = "SMTP"
 And _
  .Email1DisplayName <> 
  .Email1Address Then

If the address is an Internet address and the two properties are different, the subroutine copies the address to a string variable, sets the Email1Address property to an empty string, then sets it again—this time to the original address:

strAddress = .Email1Address
.Email1Address = ""
.Email1Address = strAddress

The subroutine repeats this procedure for the Email2Address and Email3Address properties. If any of the properties required changes, the Saved property returns True, and the code saves the item.

Notice the structure that begins with the With objItem statement and finishes with the End With statement. Inside this structure, you can refer to any property or method of the item by simply prefixing the property or method with a period (e.g., .Email1Address instead of objItem.Email1Address). This tip will make your code easier to follow.

You can run the ConvertEmailDisplayToAddress procedure any time users complain that they can't see email addresses in a contacts folder. The procedure works with any contacts folder that you can see in your folder list.

End of Article



Reader Comments
Is there a way to programatically read the Global Address list to get the smtp address. This is using either VB or VBA with either CDO or the outlook application

Kenrick Robertson February 24, 2001


You must use CDO. See http://www.cdolive.com/cdo5.htm#SMTPAddressOfCurrentUser for a code fragment you should be able to adapt.

Sue Mosher March 26, 2001


What if the Email1AddressType is <> "SMTP"? In my case all my email address types are "EX" and I want to retrieve the SMTP version.

Jason December 07, 2001


it doesn't work
I tried to step into the procedure
when it goes to .Email1Address = ""
the .Email1DisplayName and .Email1Address become empty
While when it goes to the next step
.Email1Address = strAddress
it assignes the .Email1DisplayName to be the original one again.

My system platform: winXp, Outlook 2000

Any comments?

brian June 19, 2003


Thanks for the code sample. It's a good idea - but it doesn't work. I tried to actually set the display to the value of the string variable, but of course, got the error msg that the property is read-only. Isn't there a way to set that property to read-only = false? I saw how to set a control on a form to not read-only, but can't see how to do it to a field they are using behind the scenes.

It's unbelieveable to me that a program as powerful as Outlook is so incredibly lame in certain areas. This is one example - why on earth would anyone want the person's full name displayed in the email address field?? This makes no sense and is of course, redundant since we already have botrh 'full_name' and 'file_as'.

Another doozy I haven't solved yet is: how come in Outlook Express - a far less powerful tool - can you simply start typing in email addresses in the 'TO' field and each new address automatically fills in the closest match - but in Outlook you can't do this? In Outlook it takes me a lot longer to enter email addresses when sending messages, because I have to click, then type, then click again (put the person in TO, CC or BC), then type again, then click again, etc. It's making me crazy. Anyway, if you know any way of getting autofill to function, please tell me - you'd be my new best friend :)

Rachel Tafoya July 17, 2003


People in our company address book do not change. I use Outlook 2000 on a NT exchange server and get "/O=SPAN2000/OU=FIRST ADMINISTRATIVE GROUP/CN=RECIPIENTS/CN=JOHNA" for an address. I just want the company name part of the address. Thanks for any ideas.

John Alferes December 05, 2003


This code doesn't work for users in the same Microsoft Exchange Server 5.5/2000 organization, this technique shows the internal X.400 address instead of an easy-to-read SMTP address.

Shawn June 30, 2004


John & Shawn, to get the SMTP address from an Exchange sender or recipient, use CDO or Redemption and the PR_EMAIL (&H39FE001E) MAPI property to obtain the SMTP address from the AddressEntry object. See http://www.outlookcode.com/d/code/getsenderaddy.htm#redemption and http://www.cdolive.com/cdo5.htm#EMailAddressOfSender for examples.


Sue_Mosher August 19, 2004 (Article Rating: )


When I use the PR_EMAIL (&H39FE001E) field, all I get is "?????????????????"

Anonymous User November 26, 2004


Worked like a charm.

Anonymous User December 02, 2004 (Article Rating: )


You must be a registered user or online subscriber to comment on this article. Please log on before posting a comment. Are you a new visitor? Register now




Top Viewed ArticlesView all articles
Confirmed: Battery Life Issues Not Windows 7's Fault

Microsoft on Monday issued a lengthy statement about the recent Windows 7 battery controversy, echoing my assessment from earlier in the day, but backing it up with hard, cold evidence. ...

Battery Life Issues Almost Certainly Not Windows 7's Fault

While Microsoft is still investigating a notebook battery life issue that was supposedly caused by Windows 7, some interesting trends have emerged. ...

Microsoft Warns of Windows Version Expirations

Microsoft warned that this year will see three out-of-date Windows versions slip into retirement. ...


Exchange Server and Outlook Whitepapers Email Controls and Regulatory Compliance

Take Control of Your Email: Understand the Business Reasons for Email Storage Management

Related Events Top 5 Key Technologies Changing The Face of Exchange and Data Protection

Deep Dive into Windows Server 2008 R2 presented by John Savill

Bail Out Your Exchange Environment

Check out our list of Free Email Newsletters!

Exchange Server and Outlook eBooks Spam Fighting and Email Security for the 21st Century

Understanding and Leveraging Code Signing Technologies

The Expert's Guide for Exchange 2003: Preparing for, Moving to, and Supporting Exchange Server 2003

Related Exchange Server and Outlook Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format

Exchange & Outlook UPDATE eNewsletter
News, strategies, products, and developments in Exchange Server and Outlook messaging.

Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2010 Penton Media, Inc. Terms of Use | Privacy Statement