如何在Outlook中获取一个或多个邮件的发件人邮件地址?
您是否尝试过从Outlook中一个或多个已接收邮件的“发件人”字段提取电子邮件地址?本文提供了一段VBA代码,帮助您完成此任务。
从Outlook中的一个或多个邮件中获取发件人的电子邮件地址
请运行以下VBA代码,以从Outlook中一个或多个已接收邮件的“发件人”字段提取电子邮件地址。
1. 打开一个邮件文件夹,选择一封您想获取发件人邮件地址的邮件。按 Alt + F11 键打开 Microsoft Visual Basic for Applications 窗口。
注意:要选择多封邮件,请按住 Ctrl 键,然后逐一选择邮件。
2. 在 Microsoft Visual Basic for Applications 窗口中,点击 插入 > 模块,然后将以下VBA代码复制到模块(代码)窗口中。

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. 点击 工具 > 引用,然后在 “引用 – Project1”对话框中勾选 Microsoft Scripting Runtime 选项。

4. 按 F5 键运行代码。随后会弹出一个 Kutools for Outlook 对话框,列出所选邮件的所有发件人电子邮件地址。
注意:

5. 点击 是 按钮后,会弹出一个“浏览文件夹”对话框。请选择一个文件夹保存文件并点击 确定 按钮。

6. 最后,会弹出一个 Kutools for Outlook 对话框,告知您导出文件的路径。点击 确定 关闭它。

7. 转到保存导出文件的文件夹,并打开名为 Address 的.txt文件,查看所选邮件的发件人电子邮件地址。

最佳 Office 办公效率工具
重磅消息:Kutools for Outlook 推出免费版本!
体验全新 Kutools for Outlook 免费版,70 多个强大功能,永久免费使用!点击立即下载!
🤖 Kutools AI :利用先进的AI技术轻松处理邮件,包括答复、总结、优化、扩展、翻译和撰写邮件。
📧 邮件自动化:自动答复(支持POP和IMAP) /计划发送邮件 /发送邮件时根据规则自动抄送密送 / 自动转发(高级规则) / 自动添加问候语 / 自动将群发邮件拆分为单独邮件 ...
📨 邮件管理:撤回邮件 / 按主题等方式阻止诈骗邮件 / 删除重复邮件 / 高级搜索 / 整合文件夹 ...
📁 附件专家:批量保存 / 批量拆离 / 批量压缩 / 自动保存 / 自动拆离 / 自动压缩 ...
🌟 界面魔法:😊更多精美个性表情 /重要邮件来临时提醒您 / 最小化而非关闭 Outlook ...
👍 一键高效操作:带附件全部答复 /反钓鱼邮件 / 🕘显示发件人时区 ...
👩🏼🤝👩🏻 联系人与日历:从选中的邮件批量添加联系人 / 将联系人组拆分为多个独立组 / 移除生日提醒 ...
使用 Kutools,支持英语、西班牙语、德语、法语、中文及40 多种其他语言,满足您的语言偏好!
一键解锁 Kutools for Outlook。无需等待,立即下载,提升办公效率!

