savvy95
Wed Jan 25 07:16:03 CST 2006
Disregard previous message. I fixed by having the emails and the output file
in different directories. It works fine now.
So now I've retrieved a list of email addresses. I guess the next step is
to email the list with a canned response. No?
"James Whitlow" wrote:
> "savvy95" <savvy95@discussions.microsoft.com> wrote in message
> news:A81777AF-EA8E-4113-A4EE-0DCEB2D0D273@microsoft.com...
> > Please excuse my short explanation; I was trying to be
> > The files are EML files which can be read like TXT files. The files
> contain
> > multiple lines; but I'm looking for the email address after "Email :. And
> you
> > assumed correctly, I need to parse each file.
>
> Give the below code a try and see if it does what you are looking for. It
> is a little rough, so you might have to post back with the error message(s)
> and/or undesired results. Make sure to customize the variables on lines 13 &
> 14 for your environment.
>
> The code below only addresses the first part of your problem. If it works,
> we can move on to part 2. Also, when I saved out some email message from
> Outlook Express, I did not have an "Email: " header, but rather a "From: "
> header, so that is the way I wrote the code. If your EML messages actually
> use "Email: ", alter line 11.
>
> Lastly, please consider that using regular expressions to match email
> addresses is somewhat dubious. It will probably work for most email
> addresses, but might misidentify some. See this thread for some recent
> discussions of this issue:
http://tinyurl.com/a2c9q
>
> '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Dim oFSO, sFolder, oFolder, oFile, oInpFile, sOutFile
> Dim oOutFile, oRegEx, sEmlFileText
>
> Set oFSO = CreateObject("Scripting.FileSystemObject")
> Set oRegEx = CreateObject("VBScript.RegExp")
>
> oRegEx.IgnoreCase = True
> oRegEx.MultiLine = True
>
> oRegEx.Pattern = "^From:.*\b([\w!#$%&'*+-./=?^`{|}~]+@[\w-.]+)"
>
> sFolder = "C:\Emails\"
> sOutFile = "C:\Email Addresses.txt"
>
> Select Case oFSO.FolderExists(sFolder)
> Case True Set oFolder = oFSO.GetFolder(sFolder)
> Case Else
> MsgBox "Folder """ & sFolder & """ does not exist."
> End Select
>
> Set oOutFile = oFSO.OpenTextFile(sOutFile, 2, True)
>
> For Each oFile in oFolder.Files
> Set oInpFile = oFSO.OpenTextFile(oFile, 1)
> sEmlFileText = oInpFile.ReadAll
> If oRegEx.Test(sEmlFileText) Then
> oOutFile.WriteLine oRegEx.Execute(sEmlFileText)(0).Submatches(0)
> End If
> oInpFile.Close
> Next
>
> oOutFile.Close
>
> MsgBox "Done"
> '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>
>