473,407 Members | 2,314 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Retrieve List of Bounced Email Addresses from Outlook into Access

124 100+
A user is sending out a mass mailing through Outlook via Access automation. Many of these email addresses are obsolete and the email will bounce back to Outlook as "undeliverable." The user wants to update his list of email addresses in the application so that he avoids the invalid email addresses for future mailings. Is there any way to get a list of the bounced email addresses from Outlook into Access? The user can put all the bounced emails in a folder, if that helps.
Jan 16 '14 #1
5 9045
ADezii
8,834 Expert 8TB
The following Code will at least give you a listing of all E-Mails that were not deliverable. Other information should be easily extracted by using the Properties of the Outlook Item Object.
Expand|Select|Wrap|Line Numbers
  1. Dim outOutlook As New Outlook.Application
  2. Dim outNamespace As Outlook.NameSpace
  3. Dim myInbox As Outlook.MAPIFolder
  4. 'Dim myDestFolder As Outlook.MAPIFolder
  5. Dim outItems As Outlook.Items
  6. Dim outItem As Object
  7. 'Dim strFolderName As String
  8.  
  9.  
  10. Set outNamespace = outOutlook.GetNamespace("MAPI")
  11. Set myInbox = outNamespace.GetDefaultFolder(olFolderInbox)
  12.  
  13. Set outItems = myInbox.Items
  14.  
  15. DoCmd.Hourglass True
  16.  
  17. 'Retrieve the Undeliverable E-Mail Subjects
  18. For Each outItem In outItems
  19.   If InStr(outItem.Subject, "Delivery Status Notification (Failure)") > 0 Then
  20.     Debug.Print outItem.Subject
  21.   End If
  22. Next
  23.  
  24. DoCmd.Hourglass False
  25.  
  26. Set outOutlook = Nothing
  27. Set outNamespace = Nothing
  28. Set outItem = Nothing
Jan 17 '14 #2
BikeToWork
124 100+
ADezii, thanks a megabyte. I guess I would use something like outItem.EmailAddress to get the email out of it. Thanks again.
Jan 17 '14 #3
ADezii
8,834 Expert 8TB
I am not sure if EMailAddress will work in this context, but if it doesn't, the following Logic should provide an easy solution:
  1. Search every E-Mail in the Inbox analyzing its Subject to determine if it was Undeliverable. In my Code example the Search Text Delivery Status Notification (Failure) worked.
  2. For each Undeliverable, extract the E-Mail Address from the Body of the E-Mail. From what I have seen it will be enclosed within the first occurrence of '<' and a closing '>'.
  3. I would actually write these Undeliverable E-Mail Addresses to a Local table where they would be easily accessible.
  4. Do whatever you feel is best and let us know how you make out.
  5. Partial Code example follows:
    Expand|Select|Wrap|Line Numbers
    1. '****************************** CODE INTENTIONALLY OMITTED ******************************
    2. Dim intFirst As Integer         'Location of first '<'
    3. Dim intLast As Integer          'Location of first '>' after '<'
    4. Dim strBody As String           'Will hold Body Text of Undeliverable E-Mail
    5. Dim strUndlvr                   'Holds the actual Undeliverable E-Mail Address
    6.  
    7. intFirst = InStr(s, "<")
    8. intLast = InStr(intFirst + 1, s, ">")
    9.  
    10. For Each outItem In outItems    'All Items in the Inbox
    11.   If InStr(outItem.Subject, "Delivery Status Notification (Failure)") > 0 Then
    12.     strBody = outItem.Body      'Body of Undeliverable E-Mail
    13.       strUndlvr = Mid$(s, (intFirst + 1), (intLast - intFirst) - 1)     'E-Mail Address
    14.   End If
    15. Next
    16. '****************************** CODE INTENTIONALLY OMITTED ******************************
    17.  
Jan 17 '14 #4
BikeToWork
124 100+
ADezii, what is the variable "s" in your code sample? I don't see it declared and am not sure where its value is determined. Thanks for the help.
Jan 17 '14 #5
ADezii
8,834 Expert 8TB
My sincere apologies. The Variable s was simply used to simulate Text in the Body of each Undeliverable E-Mail, and to make sure that the Address Extraction Code worked as intended. I am currently at home and do not have Outlook installed and I needed a method to simulate what a typical Body Text may consist of. The proper approach would be:
Expand|Select|Wrap|Line Numbers
  1. '****************************** CODE INTENTIONALLY OMITTED ******************************
  2. Dim intFirst As Integer         'Location of first '<'
  3. Dim intLast As Integer          'Location of first '>' after '<'
  4. Dim strBody As String           'Will hold Body Text of Undeliverable E-Mail
  5. Dim strUndlvr                   'Holds the actual Undeliverable E-Mail Address
  6.  
  7. For Each outItem In outItems    'All Items in the Inbox
  8.   If InStr(outItem.Subject, "Delivery Status Notification (Failure)") > 0 Then
  9.     strBody = outItem.Body      'Body of Undeliverable E-Mail
  10.       intFirst = InStr(strBody, "<")
  11.       intLast = InStr(intFirst + 1, strBody, ">")
  12.         strUndlvr = Mid$(strBody, (intFirst + 1), (intLast - intFirst) - 1)     'E-Mail Address
  13.   End If
  14. Next
  15. '****************************** CODE INTENTIONALLY OMITTED ******************************
Jan 17 '14 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Christine Forber | last post by:
I wonder if anyone knows of some javascript code to check a comma-delimited list of email addresses for basic formating. What I'm looking for is the javascript code to check a form field on form...
0
by: Bob | last post by:
Hi Everybody I have an MS Access Database that accesses the MS Outlook Inbox. I want to be able to see the full email address that the communication has come from while within Ms Access. ...
3
by: scott_baird | last post by:
I have an email macro setup (maybe I should go another way, but that was the quickest at the moment...) and what I would like to do is automate the "to" addressee of the email it generates for...
0
by: brbxx99x | last post by:
Hi, I'm just wondering how I can display the outlook address list (the screen that is displayed when one clicks on either the TO, CC or BCC buttons) and retrieve the email addresses that the user...
4
by: Nick Bell | last post by:
The expression: preg_match_all("/text.*?(+@+\.{2,6})/i",$f, $matches); Returns ONE email address on a line in $f beginning 'text' - how do I retrieve ALL the email addresses on a line in $f...
1
by: Frank | last post by:
Hello All, I am exploring and developing a plan for a C# web app or windows app to handle bounced emails. Basically, I need to develop a system where I weed out bad addresses in our db...but...
0
by: dreamsoul620 via AccessMonster.com | last post by:
Hi all! I'm trying to set up an email application for my database. I tried linking to my Outlook address book, but when reading from the table, I receive an error message saying I need to restart...
1
by: muddasirmunir | last post by:
i want list of e-mail address from different countries so can any body guide me how to achive this task . is there any website/utility from which we can extract mail address for e-g i want mail...
45
by: Dennis | last post by:
Hi, I have a text file that contents a list of email addresses like this: "foo@yahoo.com" "tom@hotmail.com" "jerry@gmail.com" "tommy@apple.com" I like to
1
by: Sergeles | last post by:
I am currently in the process of making/maintaining a database for a school club. I started the database mostly from scratch and i have a pretty good familiarity with Access (been using it for almost...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.