How to Quickly Extract All URLs from an Outlook Email to a Text File

When receiving an email which contains multiple important URLs in the body, you may want to exact all URLs to a text file. Thus, in this article, we will introduce a method to quickly get it.

Usually, to extract the URLs from an Outlook email to a text file, you have to first create a text file and then manually copy the URLs to the file. You may think it too troublesome and are seeking a more effective means. If so, you can read on. Here we will share an approach to exporting all URLs from an email in batches.

Quickly Extract All URLs in an Email to a Text File

  1. At the outset, in your Outlook, access VBA editor according to “How to Run VBA Code in Your Outlook“.
  2. Then, copy and paste the following VBA code into an unused module.
Sub ExportURLsFromEmail2TextFile ()
    Dim objMail As Outlook.MailItem
    Dim objRegExp As RegExp
    Dim strFolder As String
    Dim objMatchCollection As MatchCollection
    Dim objMatch As Match
    Dim strURL As String
 
    'Get the source mail
    Select Case Outlook.Application.ActiveWindow.Class
           Case olInspector
                Set objMail = ActiveInspector.CurrentItem
           Case olExplorer
                Set objMail = ActiveExplorer.Selection.Item(1)
    End Select

    'Get URLs using regular expression
    Set objRegExp = New RegExp
    With objRegExp
         .Pattern = "(https?[:]//([0-9a-z=\?:/\.&-^!#$;_])*)"
         .Global = True
         .IgnoreCase = True
    End With
 
    If objRegExp.test(objMail.Body) Then
  
       'Create a new text file
       strTextFile = "E:\Hyperlinks (" & objMail.Subject & ").txt"
       Set objFileSystem = CreateObject("Scripting.FileSystemObject")
       Set objTextFile = objFileSystem.CreateTextFile(strTextFile, True)
       objTextFile.WriteLine ("Extracted URLs:" & vbCrLf & vbCrLf)
 
       Set objMatchCollection = objRegExp.Execute(objMail.Body)
       i = 0
       For Each objMatch In objMatchCollection
           strURL = objMatch.SubMatches(0)
           i = i + 1
 
           'Write the URLs to the text file
           objTextFile.WriteLine (i & ". " & strURL & vbCrLf)
       Next
 
       objTextFile.Close
       'Open the text file
       Shell ("notepad.exe " & strTextFile)
    End If
End Sub

VBA Code - Extract All URLs in an Email to a Text File

  1. After that, add this macro to Quick Access Toolbar or ribbon.
  2. Finally, take the steps below to have a try.
  • First of all, select or open an email.
  • Then, click the macro button in Quick Access Toolbar or ribbon.Run Macro
  • At once, a new plain text file will be opened, in which you can see all the extracted UTLs, as shown in the following screenshot.Extracted URLs in a Text File

Beware of Risky Links in Email

Every day, you can receive all kinds of emails in your Outlook. Some are from the known contacts, and some may come from the unknown senders. In face of them, you need beware of the unknown emails, some of which may carry the suspicious links. If you open the links, your Outlook file may be infected with viruses. Then, not only will you need to kill the viruses via antivirus software, but also you have to repair the suffering PST file via a potent Outlook repair utility, like DataNumen Outlook Repair.

Author Introduction:

Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including SQL Server repair and outlook repair software products. For more information visit www.datanumen.com

Leave a Reply

Your email address will not be published. Required fields are marked *