I have a folder with several thousand emails received. Is there a way to extract the senders’ email addresses into new contacts, or a contact list, and eliminate any duplicates (of which there are many)? I am not a VB coder and if doing this requires code, does anyone have a sample?
![]() |
There are isolated problems with current patches, but they are well-known and documented on this site. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Extracting email addresses from emails (2003 SP2)
Home » Forums » AskWoody support » Productivity software by function » MS Outlook and email programs » Extracting email addresses from emails (2003 SP2)
- This topic has 17 replies, 4 voices, and was last updated 16 years, 8 months ago.
AuthorTopicWSasimpkins
AskWoody LoungerDecember 3, 2006 at 5:09 pm #437735Viewing 0 reply threadsAuthorReplies-
WSjscher2000
AskWoody LoungerDecember 3, 2006 at 5:44 pm #1041567I wonder whether you could use the export feature to export just the addresses, and then de-duplicate the list in another Office application?
A long time ago, I wrote some code that dumped email addresses out to a text file. I can’t recall whether it skipped duplicates; probably not… it might be posted here somewhere, but I didn’t find it in a search. I can look for it when I get back to the office.
-
WSasimpkins
AskWoody Lounger -
WSjscher2000
AskWoody Lounger -
WSasimpkins
AskWoody LoungerDecember 5, 2006 at 11:28 pm #1041959The attached shows what I get when I export to Excel. That’s the address of the mailing list, but if I look at individual emails, the from field shows the actual email address of the sender as ‘Offroad-request@offroadlist.com on behalf of Andrew Simpkins [andrew@xxxxx.com]’. It’s what follows the ‘on behalf of’ that I want to capture. It’s obviously in the email somewhere, but it doesn’t appear to be in an exportable field.
-
WSjscher2000
AskWoody Lounger -
WSasimpkins
AskWoody Lounger -
WSjscher2000
AskWoody LoungerDecember 6, 2006 at 9:49 pm #1042200Outlook only exposes the Sent-on-behalf-of name and not the address. You might need to move into Extended MAPI, using the Redemption library and parsing the message headers yourself. Actually, you might be able to retrieve the headers without Redemption using CDO; the only reason to prefer Redemption is the security prompts. Try the attached revised version, which retrieves the “Sender”, “From” and “Reply-To” headers (if present). You can examine the headers for messages of interest to see whether you want to collect others and put them in the strFieldList, delimited as in the current code. Please note that I used case sensitive comparisons, so there is a small chance that some nonconforming messages might slip past.
-
WSasimpkins
AskWoody LoungerDecember 7, 2006 at 2:52 am #1042243Thanks for the revised code. I was able to run it successfully.
> Outlook only exposes the Sent-on-behalf-of name and not the address.
That’s not correct, or at least it does not seem to be. If you look at an email it shows the address in the from field, enclosed in angle brackets after the name. It may be all one field but it’s parsable. I was able, using a combination of notepad and Excel, to extract the email addresses I wanted. However, I don’t seem able to import them back into an Outlook contacts folder. I exported them to an Excel spreadsheet with two columns, one for name and one for email address. When I try to import this back into Outlook, the ‘Map custom fields’ button is greyed out, so I can’t tell Outlook where to put the data. If I click on ‘Continue’ without mapping custom fields, Outlook just sits there for ever until I click ‘Cancel’.
-
WSjscher2000
AskWoody LoungerDecember 7, 2006 at 5:04 am #1042259Sorry, when I used the word “exposes,” I meant as a property of the MailItem object, as part of the Outlook object model.
I have no idea what is going wrong with your import. If you can’t map your columns, try using Outlook’s exact field names in the first row. To get the field names, export some sample data.
-
WSasimpkins
AskWoody LoungerDecember 7, 2006 at 5:18 pm #1042383My fault. I omitted to check the box in front of the source file! As soon as I did that I was able to map the fields. I was able to separate the name and address into two fields by using Notepad’s “find and replace” to replace the right angle bracket with a blank, loading the file into Excel and parsing it using the left angle bracket as a delimiter. Voila! Thanks for your help.
-
WSJohnBF
AskWoody LoungerDecember 7, 2006 at 1:28 pm #1042326I had separately determined that the underlying address of the person for whom the message is “SentOnBehalfOfName” is not exposed in the Outlook VBA model, but did not get back to the Lounge until now. As Jefferson states, you’ll need to use Redemption or CDO or another library to expose that information.
Outlook is very annoying in regard to the limits of its object model, especially compared to othe Office apps, but MS probably limits the Outlook Object model to reduce the use of Outlook as a Spam and virus propagation engine.
-
-
-
DaveA
AskWoody_MVPDecember 5, 2006 at 2:19 am #1041755 -
WSJohnBF
AskWoody LoungerSeptember 25, 2008 at 9:42 am #1041954FWIW, attached is some VBA code that will add Addresses to your default Contacts folder. It checks that the Contact exists by checking only for an exact match on the Contact FileAs Field. If the FileAs field match fails, a new Contact will be created, with the email address. If the Contact is found but the email address is not among the three records, and there is an unused address of the three available, the email address will be added to that Contact. The code is written for messages selected from the Folder view, not the individual open message item.
The code may need further testing (and doesn’t win any awards for elegance).
-
WSasimpkins
AskWoody LoungerDecember 5, 2006 at 11:43 pm #1041961Thanks for the code sample. In the line “Set colContacts = Outlook.Session.GetDefaultFolder(olFolderContacts).Items” I presume this selects the currently selected folder, yes? I have about 300 Outlook mail folders. Where does the code send the output? See my post 618,294. Does this have any impact on the code?
-
WSJohnBF
AskWoody LoungerDecember 6, 2006 at 6:54 pm #1041964From your other post it appears that you need to extract the “SentOnBehalfOfName”. The code I provided does not look for that, but it would be easy to obtain; I may have to see if there any complications to getting the SMPT address from the Sender line, it may have to be parsed.
> Set colContacts = Outlook.Session.GetDefaultFolder(olFolderContacts).Items
selects the default contacts folder, not the folder where the messages reside. The code doesn’t extract anything, as the text states it adds the address as a Contact in your default Contacts Folder.
The line
Set selSelItems = Outlook.ActiveExplorer.Selection
is where the items you have manually selected (by clicking, or Shift-clicking or Ctrl-clicking for multiples) in a Message Folder are brought into the code as the Items to be acted on. As written, the code is not intended to loop through 300 folders, it’s intended to work on manually selected items in a folder. Looping through multiple folders can be done but it is additional work I won’t be able to get to, and such code would have to examine every item in the folders, so it might take some time to run.
-
WSasimpkins
AskWoody LoungerDecember 6, 2006 at 6:22 pm #1042145Thanks for the clarification.
> Set selSelItems = Outlook.ActiveExplorer.Selection is where the items you have manually selected (by clicking, Shift-clicking or Ctrl-clicking for multiples)
That’s good; I don’t want it to loop through all the mail folders, just the one selected.
> Set colContacts = Outlook.Session.GetDefaultFolder(olFolderContacts).Items selects the default contacts folder
I’m not sure which is the default contacts folder. Is that the root ‘Contacts’ folder? If it’s the root folder, that would be OK as there is nothing in that.
-
WSJohnBF
AskWoody Lounger
-
-
-
-
Viewing 0 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
KB5058405 might fail to install with recovery error 0xc0000098 in ACPI.sys
by
Susan Bradley
4 hours, 6 minutes ago -
T-Mobile’s T-Life App has a “Screen Recording Tool” Turned on
by
Alex5723
6 hours, 48 minutes ago -
Windows 11 Insider Preview Build 26100.4202 (24H2) released to Release Preview
by
joep517
1 hour, 22 minutes ago -
Windows Update orchestration platform to update all software
by
Alex5723
14 hours, 7 minutes ago -
May preview updates
by
Susan Bradley
1 hour, 30 minutes ago -
Microsoft releases KB5061977 Windows 11 24H2, Server 2025 emergency out of band
by
Alex5723
3 hours, 41 minutes ago -
Just got this pop-up page while browsing
by
Alex5723
6 hours, 19 minutes ago -
KB5058379 / KB 5061768 Failures
by
crown
3 hours, 23 minutes ago -
Windows 10 23H2 Good to Update to ?
by
jkitc
32 minutes ago -
At last – installation of 24H2
by
Botswana12
1 day, 5 hours ago -
MS-DEFCON 4: As good as it gets
by
Susan Bradley
44 minutes ago -
RyTuneX optimize Windows 10/11 tool
by
Alex5723
1 day, 17 hours ago -
Can I just update from Win11 22H2 to 23H2?
by
Dave Easley
1 day, 11 hours ago -
Limited account permission error related to Windows Update
by
gtd12345
2 days, 7 hours ago -
Another test post
by
gtd12345
2 days, 7 hours ago -
Connect to someone else computer
by
wadeer
2 days, 1 hour ago -
Limit on User names?
by
CWBillow
2 days, 5 hours ago -
Choose the right apps for traveling
by
Peter Deegan
1 day, 18 hours ago -
BitLocker rears its head
by
Susan Bradley
1 day, 2 hours ago -
Who are you? (2025 edition)
by
Will Fastie
1 day, 1 hour ago -
AskWoody at the computer museum, round two
by
Will Fastie
1 day, 21 hours ago -
A smarter, simpler Firefox address bar
by
Alex5723
2 days, 17 hours ago -
Woody
by
Scott
3 days, 3 hours ago -
24H2 has suppressed my favoured spider
by
Davidhs
1 day, 2 hours ago -
GeForce RTX 5060 in certain motherboards could experience blank screens
by
Alex5723
3 days, 17 hours ago -
MS Office 365 Home on MAC
by
MickIver
3 days, 11 hours ago -
Google’s Veo3 video generator. Before you ask: yes, everything is AI here
by
Alex5723
4 days, 7 hours ago -
Flash Drive Eject Error for Still In Use
by
J9438
1 day, 2 hours ago -
Windows 11 Insider Preview build 27863 released to Canary
by
joep517
5 days, 2 hours ago -
Windows 11 Insider Preview build 26120.4161 (24H2) released to BETA
by
joep517
5 days, 2 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.