如何從 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 彈出對話框,列出所選電子郵件的所有發件人電子郵件地址。
保養竅門:
如果您需要將地址列表導出為 txt 文件,請單擊 是 按鈕。
或點擊 沒有 按鈕以結束該過程。
5。 點擊後 是 按鈕,一個 瀏覽文件夾 對話框彈出。 請選擇一個文件夾來保存文件,然後單擊 OK 按鈕。
6.最後, Kutools for Outlook 將彈出對話框,告訴您導出文件的路徑。 點擊 OK 關閉它。
7. 到保存導出文件的文件夾,打開名為.txt 的文件 地址 查看所選電子郵件的發件人電子郵件地址。
Kutools for Outlook-為Outlook帶來100個高級功能,並使工作更加輕鬆!
- 自動CC / BCC 根據規則發送電子郵件; 自動前進 自定義多封電子郵件; 自動回复 沒有交換服務器,還有更多自動功能...
- BCC警告 -當您嘗試全部答复時顯示消息 如果您的郵件地址在“密件抄送”列表中; 缺少附件時提醒,還有更多提醒功能...
- 在郵件對話中回复(全部)帶有所有附件; 回复許多電子郵件 片刻之間; 自動添加問候語 回复時將日期添加到主題中...
- 附件工具:管理所有郵件中的所有附件, 自動分離, 全部壓縮,重命名全部,保存全部...快速報告, 計算選定的郵件...
- 強大的垃圾郵件 習俗 刪除重複的郵件和聯繫人... 使您能夠在Outlook中做得更聰明,更快和更好。

