Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  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 log on before posting a comment.

If you don't have a username & password, please register now.




Top Viewed ArticlesView all articles
WinInfo Short Takes: Week of November 24, 2008

An often irreverent look at some of the week's other news, including a Vista Capable dismissal request, Zune price reductions, Morrow musings, Novell and Microsoft sitting in a tree ... two years later, Yahoo!, IE 6 on Windows Mobile, and so much more ...

Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

PsExec

This freeware utility lets you execute processes on a remote system and redirect output to the local system. ...


Exchange Server and Outlook Whitepapers Protecting (You and) Your Data with Exchange Server 2007

StoreVault SnapManagers for Microsoft Exchange and SQL Server

Related Events The Myths & Truths of Email Management with SharePoint

Top 10 Email Security Challenges and Solutions

Mastering Exchange 2007 Server Management – May 29, 2008 (11:00 AM EST)

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 Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.

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 Windows Dev Pro IT Job Hound ITTV
IT Library Technology Resource Directory Connected Home Windows Excavator Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2008 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing