Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6887501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:53:33+00:00 2026-05-27T05:53:33+00:00

I have about 17k emails containing orders, news, contacts etc. going back 11 years.

  • 0

I have about 17k emails containing orders, news, contacts etc. going back 11 years.

Users’ email addresses have been shoddily encrypted to stop crawlers and spam by changing the @ to either *@* or 'at'.

I am trying to create a comma separated list to build a database of our users.

The code works with writing the file and looping the folders because if I write the senders email address to the file where I am currently using the body of the email then it prints fine.

The problem is, the Replaces aren’t changing *at* etc to @.

  1. First of all, why not?
  2. Is there a better way for me to be doing this as a whole?
Private Sub Form_Load()

   Dim objOutlook As New Outlook.Application
   Dim objNameSpace As Outlook.NameSpace
   Dim objInbox As MAPIFolder
   Dim objFolder As MAPIFolder
   Dim fldName As String

   fldName = "TEST"

   ' Get the MAPI reference

   Set objNameSpace = objOutlook.GetNamespace("MAPI")

   ' Pick up the Inbox

   Set objInbox = objNameSpace.GetDefaultFolder(olFolderInbox)

   'Loop through the folders under the Inbox
   For Each objFolder In objInbox.Folders
       RecurseFolders fldName, objFolder
   Next objFolder

End Sub

Public Sub RecurseFolders(targetFolder As String, currentFolder As MAPIFolder)
   If currentFolder.Name = targetFolder Then
       GetEmails currentFolder
   Else
       Dim objFolder As MAPIFolder
       If currentFolder.Folders.Count > 0 Then
           For Each objFolder In currentFolder.Folders
               RecurseFolders targetFolder, objFolder
           Next
       End If
     End If
End Sub

Sub WriteToATextFile(e As String)
    MyFile = "c:\" & "emailist.txt"
    'set and open file for output
    fnum = FreeFile()
    Open MyFile For Append As fnum
    Print #fnum, e; ","
    Close #fnum
End Sub

Sub GetEmails(folder As MAPIFolder)
    Dim objMail As MailItem

    ' Read through all the items
    For i = 1 To folder.Items.Count
        Set objMail = folder.Items(i)
        GetEmail objMail.Body              
    Next i

End Sub

Sub GetEmail(s As String)
    Dim txt = s
    Do Until InStr(txt, "@") <= 0
        Dim tleft As Integer
        Dim tright As Integer
        Dim start As Integer
        Dim text As String
        Dim email As String

        text = Replace(text, " at ", "@", VbCompareMethod.vbTextCompare)
        text = Replace(text, "'at'", "@", VbCompareMethod.vbTextCompare)
        text = Replace(text, "*at*", "@", VbCompareMethod.vbTextCompare)
        text = Replace(text, "*at*", "@", VbCompareMethod.vbTextCompare)

        text = Replace(text, "<", " ", VbCompareMethod.vbTextCompare)
        text = Replace(text, ">", " ", VbCompareMethod.vbTextCompare)
        text = Replace(text, ":", " ", VbCompareMethod.vbTextCompare)

        'one two ab@bd.com one two
        tleft = InStr(text, "@") '11

        WriteToATextFile Str(tleft)
        WriteToATextFile Str(Len(text))

        start = InStrRev(text, " ", Len(text) - tleft)
        'WriteToATextFile Str(start)
        'WriteToATextFile Str(Len(text))
        'start = Len(text) - tleft
        text = left(text, start)
        'ab@bd.com one two

        tright = InStr(text, " ") '9
        email = left(text, tright)
        WriteToATextFile email

        text = right(text, Len(text) - Len(email))
        GetEmail txt
    Loop
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:53:33+00:00Added an answer on May 27, 2026 at 5:53 am

    I’ve taken a crack at this to extract emails such as this sample below which will take out the three email addresses in yellow in the sample message below to a csv file

    1. Any valids emails are written to a csv file Set objTF = objFSO.createtextfile("c:\myemail.csv")
    2. This code scans all emails in a folder called temp under Inbox I cut out your recursive portion of testing and simplicity
    3. There are four string manipulations
    4. This line converts any non printing blank spaces to normal spaces strMsgBody = Replace(strMsgBody, Chr(160), Chr(32) (unlikely but it happened in my testing)
    5. Regex1 converts any ” at ” or “at” etc into “@” "(\s+at\s+|'at'|<at>|\*at\*|at)"
    6. Regex2 converts any ” dot ” or “dot” etc into “.” "(\s+dot\s+|'dot'|<dot>|\*dot\*|dot)"
    7. Regex3 converts any of “<” “>” or “:” into “” .Pattern = "[<:>]"
    8. Regex4 extracts any valid email from the emailbody
    9. Any valid emails are written to the csv file using objTF.writeline objRegM

      enter image description here

    Code below

    Public Test()
    Dim objOutlook As New Outlook.Application
    Dim objNameSpace As Outlook.NameSpace
    Dim objFolder As MAPIFolder
    Dim strfld As String
    Dim objRegex As Object
    Dim objRegMC As Object
    Dim objRegM As Object
    Dim objFSO As Object
    Dim oMailItem As MailItem
    Dim objTF As Object
    Dim strMsgBody As String    
    Set objRegex = CreateObject("vbscript.regexp")
    Set objFSO = CreateObject("scripting.filesystemobject")
    Set objTF = objFSO.createtextfile("c:\myemail.csv")
    
    With objRegex
        .Global = True
        .MultiLine = True
        .ignorecase = True
        strfld = "temp"
        'Get the MAPI reference
        Set objNameSpace = objOutlook.GetNamespace("MAPI")
        'Pick up the Inbox
        Set objFolder = objNameSpace.GetDefaultFolder(olFolderInbox)
        Set objFolder = objFolder.Folders(strfld)
        For Each oMailItem In objFolder.Items
            strMsgBody = oMailItem.Body
            strMsgBody = Replace(strMsgBody, Chr(160), Chr(32))
            .Pattern = "(\s+at\s+|'at'|<at>|\*at\*|at)"
            strMsgBody = .Replace(strMsgBody, "@")
            .Pattern = "(\s+dot\s+|'dot'|<dot>|\*dot\*|dot)"
            strMsgBody = .Replace(strMsgBody, ".")
            .Pattern = "[<:>]"
            strMsgBody = .Replace(strMsgBody, vbNullString)
            .Pattern = "[\w-\.]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,3}"
            If .Test(strMsgBody) Then
                Set objRegMC = .Execute(strMsgBody)
                For Each objRegM In objRegMC
                    objTF.writeline objRegM
                Next
            End If
        Next
    End With
    objTF.Close
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have about 4-5 years of background in programming some in C# and some
I have about 3-4 canvas controls and each contains about 750-1200 paths. Users needs
I have about 50 arrays filled with numbers and I have to report out
I have about 20 grid views that I have to create. All of them
i have about 60 fragments ListFragment , now i use each Listfragment with another
I have about 8 entities that all have a one to one relationship with
i have about 20 possible exception messages that i want thrown when an error
I have about 1 million records in my contact table in the DB, now
I have about 700 items to display in the grid view. On a Samsung
I have about 1500 images within a folder named 3410001ne => 3809962sw. I need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.