Solved

Get email address of original receipient(s) out of a returned non deliverable email reply.

Posted on 2010-09-06
4
373 Views
Last Modified: 2013-11-27
Hi Experts,
I'm regularily I'm sending out hundreds of email via mailmerge with Winword. Many emails addresses are invalid and therefore I receive hundreds replies (e.g. "Undelievered Mail Return", "Message delivery notice","Delivery FAilure",...).
Currently I'm archiving all this received NDR within an Outlook folder, and have this Outlook folder linked the folder within MSAccess2007 so that I can access them and retrieve info via MAPI calls. However I cannot get the origianl receipients email address. In order to clean up my customer database by removing the invalid email addresses I'm looking for:

MSAccess VBA code which programmatically goes through all emails in the linked outlook folder and writes the original senders email address (where mail could not be delivered) into a MSAccess table.

Thanks in advace for your help-
Martin
0
Comment
Question by:MartinNeubauer
4 Comments
 
LVL 6

Accepted Solution

by:
OxonDev earned 500 total points
ID: 33612598
Hi Martin,

If you want to loop through a folders mail items you can use this:

Public Sub LoopEMail()
'Needs reference to C:\Program Files\Microsoft Office\Office12\MSOUTL.OLB or similar
On Error GoTo Err_LoopEMail

Dim objNamespace As Namespace
Dim objInboxFolder As MAPIFolder
Dim objMailItem As MailItem
Dim objSubFolder As MAPIFolder

    Set objNamespace = GetNamespace("MAPI")
    Set objInboxFolder = objNamespace.GetDefaultFolder(olFolderInbox)
   
    If objInboxFolder.Items.Count = 0 Then GoTo Exit_LoopEMail

    For Each objMailItem In objInboxFolder.Items
        Debug.Print objMailItem.Subject
    Next objMailItem

Exit_LoopEMail:
    Exit Sub

Err_LoopEMail:
    MsgBox "LoopEMail Error " & Err.Number & ": " & Err.Description
    Resume Exit_LoopEMail
End Sub

There's further info in thsi article for navigating  specific folders:  http://www.outlookcode.com/d/code/getfolder.htm

However, that'll only get you half way as the recipients list of each mail item will be you...  I'd suggest you grab the body text & compare it with your contacts list.  Usually the body will contain a reference to unable to deliver to InvalidAddress@Unknown.com

However, this would only work if you sent to one address at a time as some include successful addresses as well.
0
 

Author Comment

by:MartinNeubauer
ID: 33615246
Hi OxonDev,

thanks, yes this helps me to access mail by mail. I thought to parse somehow the content for email as you mentioned, but the content in those mails look very different.
Note: Yes, I only send to one receipient at a time.
Well Step 1 (accessing mail individually) done :-)

I remember somebody said that somehwere within a mail (header?) additional info (like mail receipients history, transporting mailservers, etc should be available. Hopefully that's true and  we can retrieve this.
Any other ideas to get Step 2 (mailhistory, original receipients)

Thanks,
Martin
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 34118953
This question has been classified as abandoned and is being closed as part of the Cleanup Program.  See my comment at the end of the question for more details.
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question