如何從 Outlook 中的一封或多封電子郵件中獲取發件人的電子郵件地址?
您是否嘗試過從 Outlook 中收到的一封或多封電子郵件的「寄件者」欄位中提取電子郵件地址?本文提供了一個 VBA 程式碼來幫助您處理此任務。
從 Outlook 中的一封或多封電子郵件中獲取發件人的電子郵件地址
請執行以下 VBA 程式碼,從 Outlook 中收到的一封或多封電子郵件的「寄件者」欄位中提取電子郵件地址。
1. 打開電子郵件文件夾,選擇要從中獲取發件人電子郵件地址的電子郵件。 請按 其他 + F11 鍵打開 Microsoft Visual Basic for Applications 窗口。
更多竅門: 要選擇多封電子郵件,請按住 按Ctrl 鍵,然後一一選擇電子郵件。
2。 在裡面 Microsoft Visual Basic for Applications 窗口中,單擊 插入 > 模塊,然後將以下VBA代碼複製到Module(代碼)窗口。

VBA 代碼:從 Outlook 中的一封或多封電子郵件中提取發件人的電子郵件地址
Sub GetSmtpAddressOfSelectionEmail()
Dim xExplorer As Explorer
Dim xSelection As Selection
Dim xItem As Object
Dim xMail As MailItem
Dim xAddress As String
Dim xFldObj As Object
Dim FilePath As String
Dim xFSO As Scripting.FileSystemObject
On Error Resume Next
Set xExplorer = Application.ActiveExplorer
Set xSelection = xExplorer.Selection
For Each xItem In xSelection
If xItem.Class = olMail Then
Set xMail = xItem
xAddress = xAddress & VBA.vbCrLf & " " & GetSmtpAddress(xMail)
End If
Next
If MsgBox("Sender SMTP Address is: " & xAddress & vbCrLf & vbCrLf & "Do you want to export the address list to a txt file? ", vbYesNo, "Kutools for Outlook") = vbYes Then
Set xFldObj = CreateObject("Shell.Application").BrowseforFolder(0, "Select a Folder", 0, 16)
Set xFSO = New Scripting.FileSystemObject
If xFldObj Is Nothing Then Exit Sub
FilePath = xFldObj.Items.Item.Path & "\Address.txt"
Close #1
Open FilePath For Output As #1
Print #1, "Sender SMTP Address is: " & xAddress
Close #1
Set xFSO = Nothing
Set xFldObj = Nothing
MsgBox "Address list has been exported to:" & FilePath, vbOKOnly + vbInformation, "Kutools for Outlook"
End If
End Sub
Function GetSmtpAddress(Mail As MailItem)
Dim xNameSpace As Outlook.NameSpace
Dim xEntryID As String
Dim xAddressEntry As AddressEntry
Dim PR_SENT_REPRESENTING_ENTRYID As String
Dim PR_SMTP_ADDRESS As String
Dim xExchangeUser As exchangeUser
On Error Resume Next
GetSmtpAddress = ""
Set xNameSpace = Application.Session
If Mail.sender.Type <> "EX" Then
GetSmtpAddress = Mail.sender.Address
Else
PR_SENT_REPRESENTING_ENTRYID = "http://schemas.microsoft.com/mapi/proptag/0x00410102"
xEntryID = Mail.PropertyAccessor.BinaryToString(Mail.PropertyAccessor.GetProperty(PR_SENT_REPRESENTING_ENTRYID))
Set xAddressEntry = xNameSpace.GetAddressEntryFromID(xEntryID)
If xAddressEntry Is Nothing Then Exit Function
If xAddressEntry.AddressEntryUserType = olExchangeUserAddressEntry Or xAddressEntry.AddressEntryUserType = olExchangeRemoteUserAddressEntry Then
Set xExchangeUser = xAddressEntry.GetExchangeUser()
If xExchangeUser Is Nothing Then Exit Function
GetSmtpAddress = xExchangeUser.PrimarySmtpAddress
Else
PR_SMTP_ADDRESS = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"
GetSmtpAddress = xAddressEntry.PropertyAccessor.GetProperty(PR_SMTP_ADDRESS)
End If
End If
End Function
3。 點擊 工具 > 參考,然後檢查 Microsoft腳本運行時 盒子裡 參考 - 項目1 對話框。

4。 按 F5 鍵來運行代碼。 然後一個 Kutools for Outlook 彈出對話框,列出所選電子郵件的所有發件人電子郵件地址。
更多竅門:

5。 點擊後 可以 按鈕,一個 瀏覽文件夾 對話框彈出。 請選擇一個文件夾來保存文件,然後單擊 OK 按鈕。

6.最後, Kutools for Outlook 將彈出對話框,告訴您導出文件的路徑。 點擊 OK 關閉它。

7. 到保存導出文件的文件夾,打開名為.txt 的文件 地址 查看所選電子郵件的發件人電子郵件地址。

最佳辦公生產力工具
突發新聞:Kutools for Outlook 發布 免費版本!
體驗全新的Kutools for Outlook 免費版本擁有 70 多個令人難以置信的功能,您可以永遠使用! 點擊立即下載!
🤖 Kutools人工智慧 : 使用先進的人工智慧技術輕鬆處理電子郵件,包括回覆、總結、優化、擴展、翻譯和撰寫電子郵件。
📧 電子郵件自動化: 自動回覆(適用於 POP 和 IMAP) / 安排發送電子郵件 / 發送電子郵件時按規則自動抄送/密件副本 / 自動轉送(進階規則) / 自動添加問候語 / 自動將多收件者電子郵件拆分為單獨的訊息 ...
📨 電子郵件管理: 撤回電子郵件 / 按主題和其他人阻止詐騙電子郵件 / 刪除重複的電子郵件 / 進階搜索 / 合併資料夾 ...
📁 附件專業版: 批量保存 / 批量分離 / 批量壓縮 / 自動保存 / 自動分離 / 自動壓縮 ...
🌟 介面魔法: 😊更多又漂亮又酷的表情符號 / 當重要電子郵件到來時提醒您 / 最小化 Outlook 而不是關閉 ...
👍 一鍵奇蹟: 使用傳入附件回覆全部 / 反網路釣魚電子郵件 / 🕘顯示寄件者的時區 ...
👩🏼🤝👩🏻 通訊錄和行事曆: 從選定的電子郵件中大量新增聯絡人 / 將聯絡人群組拆分為各組 / 刪除生日提醒 ...
只需單擊即可立即解鎖 Kutools for Outlook -永久免費。不要等待,立即下載並提高您的效率!

