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?
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
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, 6 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
-
two pages side by side land scape
by
marc
11 hours, 8 minutes ago -
Deleting obsolete OneNote notebooks
by
afillat
13 hours, 14 minutes ago -
Word/Outlook 2024 vs Dragon Professional 16
by
Kathy Stevens
13 hours, 24 minutes ago -
Security Essentials or Defender?
by
MalcolmP
13 hours, 27 minutes ago -
April 2025 updates out
by
Susan Bradley
27 minutes ago -
Framework to stop selling some PCs in the US due to new tariffs
by
Alex5723
1 hour, 34 minutes ago -
WARNING about Nvidia driver version 572.83 and 4000/5000 series cards
by
Bob99
15 hours, 42 minutes ago -
Creating an Index in Word 365
by
CWBillow
4 hours, 47 minutes ago -
Coming at Word 365 and Table of Contents
by
CWBillow
5 hours, 2 minutes ago -
Windows 11 Insider Preview Build 22635.5170 (23H2) released to BETA
by
joep517
1 day, 8 hours ago -
Has the Microsoft Account Sharing Problem Been Fixed?
by
jknauth
1 day, 11 hours ago -
W11 24H2 – Susan Bradley
by
G Pickerell
1 day, 13 hours ago -
7 tips to get the most out of Windows 11
by
Alex5723
1 day, 11 hours ago -
Using Office apps with non-Microsoft cloud services
by
Peter Deegan
1 day, 4 hours ago -
I installed Windows 11 24H2
by
Will Fastie
7 hours, 19 minutes ago -
NotifyIcons — Put that System tray to work!
by
Deanna McElveen
1 day, 16 hours ago -
Decisions to be made before moving to Windows 11
by
Susan Bradley
6 hours, 49 minutes ago -
Port of Seattle says ransomware breach impacts 90,000 people
by
Nibbled To Death By Ducks
2 days, 1 hour ago -
Looking for personal finance software with budgeting capabilities
by
cellsee6
1 day, 9 hours ago -
ATT/Yahoo Secure Mail Key
by
Lil88reb
1 day, 9 hours ago -
Devices with apps using sprotect.sys driver might stop responding
by
Alex5723
2 days, 18 hours ago -
Neowin – 20 times computers embarrassed themselves with public BSODs and goofups
by
EP
3 days, 2 hours ago -
Slow Down in Windows 10 performance after March 2025 updates ??
by
arbrich
2 days, 5 hours ago -
Mail from certain domains not delivered to my outlook.com address
by
pumphouse
2 days, 11 hours ago -
Is data that is in OneDrive also taking up space on my computer?
by
WShollis1818
2 days, 21 hours ago -
Nvidia just fixed an AMD Linux bug
by
Alex5723
4 days, 13 hours ago -
50 years and counting
by
Susan Bradley
1 day, 11 hours ago -
Fix Bluetooth Device Failed to Delete in Windows Settings
by
Drcard:))
1 day, 14 hours ago -
Licensing and pricing updates for on-premises server products coming July 2025
by
Alex5723
5 days ago -
Edge : Deprecating window.external.getHostEnvironmentValue()
by
Alex5723
5 days 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.