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
-
Uninstalr Updates
by
jv16
2 hours, 34 minutes ago -
Apple zero days for April
by
Susan Bradley
5 hours, 20 minutes ago -
CVE program gets last-minute funding from CISA – and maybe a new home
by
Nibbled To Death By Ducks
3 hours, 22 minutes ago -
Whistleblower describes DOGE IT dept rumpus at America’s labor watchdog
by
Nibbled To Death By Ducks
15 hours, 11 minutes ago -
Seeing BSOD’s on 24H2?
by
Susan Bradley
1 hour, 30 minutes ago -
TUT For Private Llama LLM, Local Installation and Isolated from the Internet.
by
bbearren
5 hours, 35 minutes ago -
Upgrade from Windows 10 to 11
by
Holdsworth8
23 hours, 51 minutes ago -
Microsoft : AI-powered deception: Emerging fraud threats and countermeasures
by
Alex5723
1 day, 2 hours ago -
0patch
by
WSjcgc50
3 hours, 39 minutes ago -
Devices might encounter blue screen exception with the recent Windows updates
by
Susan Bradley
20 hours, 3 minutes ago -
Windows 11 Insider Preview Build 22631.5261 (23H2) released to Release Preview
by
joep517
1 day, 5 hours ago -
Problem opening image attachments
by
RobertG
1 day, 7 hours ago -
advice for setting up a new windows computer
by
routtco1001
1 day, 22 hours ago -
It’s Identity Theft Day!
by
Susan Bradley
1 day, 2 hours ago -
Android 15 require minimum 32GB of storage
by
Alex5723
2 days, 2 hours ago -
Mac Mini 2018, iPhone 6s 2015 Are Now Vintage
by
Alex5723
2 days, 2 hours ago -
Hertz says hackers stole customer credit card and driver’s license data
by
Alex5723
2 days, 3 hours ago -
Firefox became sluggish
by
Rick Corbett
2 days ago -
Windows 10 Build 19045.5794 (22H2) to Release Preview Channel
by
joep517
2 days, 7 hours ago -
Windows 11 Insider Preview Build 22635.5235 (23H2) released to BETA
by
joep517
2 days, 7 hours ago -
A Funny Thing Happened on the Way to the Forum
by
bbearren
1 day, 5 hours ago -
Download speeds only 0.3Mbps after 24H2 upgrade on WiFi and Ethernet
by
John
2 hours, 6 minutes ago -
T-Mobile 5G Wireless Internet
by
WSmmi16
1 day, 5 hours ago -
Clock missing above calendar in Windows 10
by
WSCape Sand
1 day, 7 hours ago -
Formula to Calculate Q1, Q2, Q3, or Q4 of the Year?
by
WSJon5
2 days, 22 hours ago -
The time has come for AI-generated art
by
Catherine Barrett
2 days, 2 hours ago -
Hackers are using two-factor authentication to infect you
by
B. Livingston
2 days, 12 hours ago -
23 and you
by
Max Stul Oppenheimer
2 days, 19 hours ago -
April’s deluge of patches
by
Susan Bradley
23 hours, 33 minutes ago -
Windows 11 Windows Updater question
by
Tex265
13 hours, 29 minutes 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.