如何从 Outlook 中的一封或多封电子邮件中获取发件人的电子邮件地址?
您是否曾尝试从 Outlook 中收到的一封或多封电子邮件的“发件人”字段中提取电子邮件地址? 本文提供了一个 VBA 代码来帮助您处理此任务。
从 Outlook 中的一封或多封电子邮件中获取发件人的电子邮件地址
请运行以下 VBA 代码从 Outlook 中收到的一封或多封电子邮件的“发件人”字段中提取电子邮件地址。
1. 打开电子邮件文件夹,选择要从中获取发件人电子邮件地址的电子邮件。 请按 其他 + F11 键打开 Microsoft Visual Basic应用程序 窗口。
小贴士: 要选择多封电子邮件,请按住 按Ctrl 键,然后一一选择电子邮件。
2。 在里面 Microsoft Visual Basic应用程序 窗口中,单击 插页 > 模块,然后将以下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中做得更聪明,更快和更好。

