Skip to main content
 

How to export email addresses based on specific domain in Outlook?

Author: Xiaoyang Last Modified: 2024-09-18

If you want to export the email addresses with a specific domain from all contacts in your Outlook, please read this tutorial which will help you to apply a VBA code for extracting all the email addresses in a specific domain to a text file as below screenshot shown.

doc-export-addresses-with-domain-1


Export email addresses based on specific domain in Outlook with VBA code

To extract all email addresses with a specific domain from all contacts, please do with the following steps:

1. Create a new text file and give a name to it, see screenshot:

doc-export-addresses-with-domain-2

2. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.

3. Then, click Insert > Module, and paste the following code in the Module Window.

VBA code: Export email addresses based on specific domain

Dim GDomain As String
Dim GFileSystem As Object
Dim GFilePath As String
Dim GFileObj As Object
Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, _
  ByVal ipOperation As String, ByVal lpFile As String, _
  ByVal lpParameters As String, ByVal lpDirectory As String, _
  ByVal nShowCmd As Long) As Long

Sub ExportListOfEmailAddressesInSpecificDomain()
'Updateby ExtendOffice
Dim xStore As Store
Dim xFolder As Folder
On Error Resume Next
GDomain = InputBox("Enter domain(@***.com):", "Kutools for Outlook")
If Len(GDomain) <> 0 Then
  GFilePath = "C:\Users\skyyang\Desktop\Email Addresses with specific domain.txt" 'Specify the file path
  Set GFileSystem = CreateObject("Scripting.FileSystemObject")
  Set GFileObj = GFileSystem.CreateTextFile(GFilePath, True)
  For Each xStore In Application.Session.Stores
    For Each xFolder In xStore.GetRootFolder.Folders
      If xFolder.DefaultItemType = olContactItem Then
        Call ProcessFolders(xFolder)
      End If
    Next
  Next
  GFileObj.Close
  ShellExecute 0&, vbNullString, GFilePath, vbNullString, vbNullString, 1
End If
End Sub

Sub ProcessFolders(ByVal Fld As Outlook.Folder)
Dim xContactItems As Items
Dim I As Long
Dim xContact As ContactItem
Dim xSubFolder As Folder
On Error Resume Next
Set xContactItems = Fld.Items
For I = xContactItems.Count To 1 Step -1
  If xContactItems(I).Class = olContact Then
    Set xContact = xContactItems(I)
    If InStr(xContact.Email1Address, GDomain) > 0 Then
      GFileObj.WriteLine (xContact.Email1Address & vbCrLf)
    ElseIf InStr(xContact.Email2Address, GDomain) > 0 Then
      GFileObj.WriteLine (xContact.Email2Address & vbCrLf)
    ElseIf InStr(xContact.Email3Address, GDomain) > 0 Then
      GFileObj.WriteLine (xContact.Email3Address & vbCrLf)
    End If
  End If
Next
If Fld.Folders.Count > 0 Then
  For Each xSubFolder In Fld.Folders
    If xSubFolder.DefaultItemType = olContactItem Then
      Call ProcessFolders(xSubFolder)
    End If
  Next
End If
End Sub
Note: In the above code, change the file path "C:\Users\skyyang\Desktop\Email Addresses with specific domain.txt" to your own.

doc-export-addresses-with-domain-4

4. And then, press F5 key to run this code. A prompt box is popped out, please type the email domain that you want to export the email addresses based on, see screenshot:

doc-export-addresses-with-domain-3

5. Then, click OK button, and all the email addresses in the specific domain are extracted into the text file at once, see screenshot:

doc-export-addresses-with-domain-1

AI Mail Assistant in Outlook: Smarter Replies, Clearer Communication (one-click magic!) FREE

Streamline your daily Outlook tasks with the AI Mail Assistant from Kutools for Outlook. This powerful tool learns from your past emails to offer intelligent and accurate responses, optimize your email content, and help you draft and refine messages effortlessly.
doc ai email handle

This feature supports:

  • Smart Replies: Get responses crafted from your past conversations—tailored, precise, and ready to go.
  • Enhanced Content: Automatically refine your email text for clarity and impact.
  • Effortless Composition: Just provide keywords, and let AI handle the rest, with multiple writing styles.
  • Intelligent Extensions: Expand your thoughts with context-aware suggestions.
  • Summarization: Get concise overviews of long emails instantly.
  • Global Reach: Translate your emails into any language with ease.

This feature supports:

  • Smart email replies
  • Optimized content
  • Keyword-based drafts
  • Intelligent content extension
  • Email summarization
  • Multi-language translation

Best of all, this feature is completely free forever! Don’t wait—download AI Mail Assistant now and enjoy!


Best Office Productivity Tools

Breaking News: Kutools for Outlook Launches Free Version!

Experience the all-new Kutools for Outlook FREE version with 70+ incredible features, yours to use FOREVER! Click to download now!

🤖 Kutools AI : Uses advanced AI technology to handle emails effortlessly, including replying, summarizing, optimizing, extending, translating, and composing emails.

📧 Email Automation: Auto Reply (Available for POP and IMAP)  /  Schedule Send Emails  /  Auto CC/BCC by Rules When Sending Email  /  Auto Forward (Advanced Rules)   /  Auto Add Greeting   /  Automatically Split Multi-Recipient Emails into Individual Messages ...

📨 Email Management: Recall Emails  /  Block Scam Emails by Subjects and Others  /  Delete Duplicate Emails  /  Advanced Search  /  Consolidate Folders ...

📁 Attachments ProBatch Save  /  Batch Detach  /  Batch Compress  /  Auto Save   /  Auto Detach  /  Auto Compress ...

🌟 Interface Magic: 😊More Pretty and Cool Emojis   /  Remind you when important emails come  /  Minimize Outlook Instead of Closing ...

👍 One-click Wonders: Reply All with Incoming Attachments  /   Anti-Phishing Emails  /  🕘Show Sender's Time Zone ...

👩🏼‍🤝‍👩🏻 Contacts & Calendar: Batch Add Contacts From Selected Emails  /  Split a Contact Group to Individual Groups  /  Remove Birthday Reminders ...

Instantly unlock Kutools for Outlook with a single click—permanently free. Don't wait, download now and boost your efficiency!

kutools for outlook features1 kutools for outlook features2