Way to weed out our Master Contact list by returned emails

Last year for Christmas I emailed out a ton of Christmas cards for our company.  The person in charge left the company and it fell to me a couple of days before our holiday shutdown so I was sending out mass emails and got around 800+ emails back saying they could not be delivered.  I tried to keep the number in batches of less than 25 recipients so we would not get flagged as spammers and some were delivered and my service was not interrupted so I don't believe that spamming is the reason those emails were returned.  Some responses were:
The server has tried to deliver this message, without success, and has stopped trying. Please try sending this message again. If the problem continues, contact your helpdesk.
A problem occurred during the delivery of this message to this e-mail address. Try sending this message again. If the problem continues, please contact your helpdesk.

The new person in charge of the Christmas list has gone through our Master Contact List and deleted duplicate names but now we want to remove or amend the contact who's emails did not work, hopefully without having someone have to manually go through each returned email and look  in the MCL to remove the contacts one at a time.  Also a supervisor feels we should get a list of these people so we can see if they are relationships that we would like to keep and re-establish contact with.

So is there a way to make a list of contacts from a mass of returned emails or from a folder in the Inbox?  Is there a way to cross-examine the returned emails with a contact list?  The Christmas list and MCL were two separate lists so it is possible people on the Christmas list may not show up on the MCL.  Does anyone have any ideas of how we can analyze the data we have in an efficient manner?  Any thoughts or suggestions would be greatly appreciated!
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

With VBA you can extract the email address (put it in a special folder, let VBA code go through it all, use regexp to retrieve the email and save it as a list).
Alternatively you add a routine to check your addressbook after each email address has been retrieved, and add someting in the results to make it clear the result was also found in the addressbook.
If this is sufficient for you, I can start on the real code. Also, what you define as a list (of email addresses), would hopefully be a subfolder in your Contacts folder filled with contacts (as opposed to a mailing list item).
HSI_guelphAuthor Commented:
We have a folder of returned emails and a contact list that might contain these emails.  Using VBA code run through Outlook?  I am not an expert with Outlook so I am not familiar with how to run code through Outlook.  Would you use the code with a command line?
I asked if that contact list you mentioned, was in fact a subfolder of contacts or a mailing list item?
Also please provide a full email (body text), or if more variants, more emails (you can replace the actual email address in the body with xx@xxx.xx)
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

HSI_guelphAuthor Commented:
Delivery has failed to these recipients or groups:

A problem occurred during the delivery of this message to this e-mail address. Try sending this message again. If the problem continues, please contact your helpdesk.


Delivery has failed to these recipients or groups:

xxxx xxxx(xxxx.xxxx@xxxx.xx)
The server has tried to deliver this message, without success, and has stopped trying. Please try sending this message again. If the problem continues, contact your helpdesk.

Looking at the messages more carefully now they don't say that the email is non-existent and there are some that say
Delivery is delayed to these recipients or groups:

xxxxx xxxxxx (xxxxxx@xxx.xx.xx)

Subject: Season Greetings from xxxxxxxxxxx® Incorporated

This message hasn't been delivered yet. Delivery will continue to be attempted.

The server will keep trying to deliver this message for the next 1 days, 19 hours and 54 minutes. You'll be notified if the message can't be delivered by that time.

which could mean that the servers were overloaded with the holiday rush.  That is why we'd like to pull those emails out and perhaps try to establish connections with people we would like to keep contact with.

And the folder structure is Master Contact list
Is there a way to extract just the emails from these messages and save them somewhere else for further evaluation?
For now, it only saves a text file with email addresses found in the body of all emails from a folder you select.

First adjust this line, to a location and file where you want to save the results:

Set stream = fso.CreateTextFile("c:\temp\foundaddresses.log", True)

Second, this requires a reference to be set in your VBA editor (ALT + F11),
a. On the Tools menu, click References.
b. In the References – VBAProject dialog box, under Available References:, scroll down to Microsoft Scripting Runtime.
c. Select the Microsoft Scripting Runtime check box, and then click OK.

Let me know if this is sufficient, or if you need to add some routine to check against some contacts list as you mentioned before. In that case, explain how the matching has to be done.

Sub getemailfrombody()

Dim myOlApp As Outlook.Application
Dim myNms As Outlook.NameSpace
Dim myFolder As Outlook.MAPIFolder

Set myOlApp = CreateObject("Outlook.Application")
Set myNms = myOlApp.GetNamespace("MAPI")
Set myFolder = myNms.PickFolder

Dim sTexts() As String
Dim i As Integer
Dim found_addresses

For Each MailItem In myFolder.Items
SText = Split(MailItem.Body, vbCrLf)
For i = LBound(SText) To UBound(SText)
 If InStr(SText(i), "@") > 0 Then
  myemail = SText(i)
  myemail = ExtractFromBody(myemail)
  If Not (myemail = "") Then
    found_addresses = myemail + vbCrLf + found_addresses
    Exit For
  End If
 End If
Next i


Dim fso As FileSystemObject
Set fso = New FileSystemObject
Dim stream As TextStream
Set stream = fso.CreateTextFile("c:\temp\foundaddresses.log", True)
stream.Write found_addresses
Set stream = Nothing
Set fso = Nothing

End Sub

Function ExtractFromBody(ByVal SText As String) As String

Dim re, match

Set re = CreateObject("vbscript.regexp")
re.Pattern = "\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b"
re.Global = True
re.IgnoreCase = True
re.MultiLine = True
For Each match In re.Execute(SText)
    ExtractFromBody = match.Value
End Function

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HSI_guelphAuthor Commented:
Thank you very much!!!  I'll post the results here when finished.
HSI_guelphAuthor Commented:
I never got back on this but this code works great and I keep coming back to it!  I just used this to create a list of returned emails and copied them into Excel where I was able to remove almost 200 duplicates and sort alphabetically which made one employee very, very happy!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.