Getting Started - Reading attachment

  • Thread starter Thread starter Diane
  • Start date Start date
D

Diane

Group,
As our company sends emails, we get a volume of returns with errors such as
mailbox full, no such user, no mailbox by that name, etc...... Some of these
messages includes an attachment "details.txt" which specifically list a
STATUS and Final-Recipient. I am looking for a getting started guide that
will help me read the attachment and pull out the status and the
"Final-Recipient. From this, I can update our email database. Any "getting
started" guides would be appreciated.
Diane
 
Outlook version?

How would you intend to code this, as an Outlook macro in VBA code, or what?

Are you an Outlook code beginner or a code beginner?

A wealth of information is at www.outlookcode.com. There's a code sample
that strips all attachments from selected emails after saving them to a temp
folder on my Web site at
http://www.slovaktech.com/code_samples.htm#StripAttachments. If you use that
code in an Outlook macro you'd just substitute the use of Application for
getting the Outlook.Application object. Outside of Outlook you'd use the
code as is.

To get the information from a text attachment you need to save it to the
file system and open it. A text file can just be opened and parsed as
strings. You can split the contents of a text file into a string array on
newlines and inspect each line to see if has any tag value you want to
parse.
 
Ken,
I'm very familiar with VBA, this is the route that I intend to take.
I've done many VBA projects in Word and some in Excel, but none with
Outlook.

I have subfolders that mail filters into within my inbox, from these
subfolders, I would like to create a program that can

1) read the header, (or the attached "details.txt" file), find the error
status,
and
2) for any invalid emails, mailbox fulls, etc....., run an sql delete
statement that will remove invalid emails from a database.

I'm good with doing step 2, it's just getting me started on step #1. I have
noticed for any "Mail Delivery" failures, that is where I find the attached
"details.txt" file. This file has the status code and the Final-Recipient
info that I would like to work with in step 1 of my VBA code.

Anyway, I believe VBA is the way that I want to go with this, if you have
other advice for this situation, I'm interested.

Thanks,
Diane
 
VBA is fine for that. The main limitation for VBA code is it's not designed
for deployment to other users, and it can't handle Outlook 2007 or 2010
Ribbon or FormRegion callbacks. Other than that it shouldn't be any problem.

The link I provided has code you can modify to strip the attachments on the
selected items and save them to temp folders. From there you should be able
to do your parsing easily if you are familiar with VBA. I used
FileSystemObject for the file processing which should be OK, and if desired
you can just remove the lines that delete the saved attachments so they
remain on the original items.

For not using only selected items but for iterating the contents of a folder
looking for items with a "details.txt" attachment you can use a procedure
that gets passed the folder and does something like this:

Dim colItems As Outlook.Items
Dim obj As Object
Dim oMail As Outlook.MailItem
Dim colAttach As Outlook.Attachments
Dim oAttach As Outlook.Attachment

Set colItems = folder.Items
For Each obj In colItems
If obj.Class = olMail then
Set oMail = obj
Set colAttach = oMail.Attachments
If colAttach.Count > 0 Then
For Each oAttach In colAttach
If oAttach.DisplayName = "details.txt" Then
' process this item

And so on.

Searching at www.outlookcode.com for specific things such as "iterating
Outlook folders" should get you samples of the other pieces you need.
 
Ken,
I finally had a chance to work with your examples and found the "Strip All
Attachments From Selected Email Items" worked instantly. I understand what
is happening here, now I need to modify so that I can iterate through the
folder and not just on a selected item. I have done something similar to
this in MS WORD and with your example below, I should be good to go.

Many Thanks for getting me started!!
Diane
 
Back
Top