How to Batch Send an Outlook Email to All Email Addresses Appearing in a Plain Text File

If you have a Plain Text file whose content contains multiple email addresses and want to quickly send an email to them, you can refer to this article. Here we will teach you how to get it with effortless ease.

When you want to send an email to all the email addresses occurring in a Plain Text file, you must long for a solution to quickly extract the email addresses from the file, instead of manually copying the email addresses. Thus, in the followings, we will teach you an effective way to achieve this.

Batch Send an Outlook Email to All Email Addresses Appearing in a Plain Text File

Batch Send an Email to All Email Addresses Appearing in a Plain Text File

  1. Here I will take my text file as an example. It looks like the screenshot below:Text File Sample
  2. For a start, launch your Outlook program.
  3. Then, access Outlook VBA editor as usual.
  4. After that, open an unused module or project.
  5. Subsequently, put the following VBA code into it.
Sub SendMailToEmailAddressesInTextFile()
    Dim strTextFile As String
    Dim objFileSystem As Object
    Dim objTextStream As Object
    Dim objMail As Outlook.MailItem
    Dim objRegExp As Object
    Dim objFoundResults As Object
    Dim i As Long
    Dim strLine As String
    Dim strEmailAddresses As String
    'Create a new email
    Set objMail = Outlook.Application.CreateItem(olMailItem)
    'Change the file path
    strTextFile = "E:\DataNumen.txt"
    Set objFileSystem = CreateObject("Scripting.FileSystemObject")
    Set objTextStream = objFileSystem.OpenTextFile(strTextFile)
    'Extract email addresses by regular expressions
    Set objRegExp = CreateObject("vbscript.RegExp")
    With objRegExp
        .Pattern = "(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|""(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\[\x01-\x09\x0b\x0c\x0e-\x7f])*"")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])"
        .IgnoreCase = True
        .Global = True
    End With
    Do Until objTextStream.AtEndOfStream
       strLine = objTextStream.ReadLine
       If strLine <> "" Then
          If objRegExp.test(strLine) Then
             Set objFoundResults = objRegExp.Execute(strLine)
             For i = 1 To objFoundResults.Count
                 strEmailAddresses = strEmailAddresses & objFoundResults.Item(i - 1).Value & "; "
          End If
       End If
    If strEmailAddresses <> "" Then 
       'Alter the email details
       With objMail
         .Recipients.Add (strEmailAddresses)
         .Subject = "Mail Subject"
         .Body = "Type mail body here"
         '.Send ==> directly send
      End With
    End If
End Sub

VBA Code - Batch Send an Email to All Email Addresses Appearing in a Plain Text File

  1. Later, you ought to change several lines of the VBA code as per your real case, such as the text file path and the email details.
  2. Eventually, you can run this macro simply by pressing “F5” key button in the current macro. Immediately, a new mail will display, in which the “To” field is filled with the email addresses extracted from the Text file.New Email
  3. If you use the “Send” line in the macro, the email will be sent out directly.

Cope with Outlook Issues Properly

Since Outlook is prone to corruption, you have to keep your PST file away from all potential risks. For instance, you ought to build the habit of closing Outlook app properly, never downloading malicious attachments and so on. Of course, you’re better off making some precautions, including making regular PST data backups and getting hold of a powerful PST fix tool, such as DataNumen Outlook Repair. It is able to resolve PST problems like a breeze.

Author Introduction:

Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including recover sql and outlook repair software products. For more information visit

Comments are closed.