在邮件的“发件人"字段中从 Exchange 用户中提取 SMTP 地址 [英] Extract SMTP address from Exchange User in the FROM field of a message
问题描述
我想按域(也可能是用户)在文件夹中组织邮件.我有一个脚本,但它无法从交换用户那里获取 SMTP 地址.以下代码摘自地址提取器.
I want to organize messages in folders by domain (and possibly user). I have a script but it can't get the SMTP addresses from exchange users. The below code is an excerpt from the address extractor.
///For each obj in objFolder.Items
If obj.SenderEmailAddress = "EX" Then
Set objSender = obj.Sender
If Not (objSender Is Nothing) Then
Set objExchUser = Sender.GetExchangeUser()
If Not (objExchUser Is Nothing) Then
strSender = objExchUser.PrimarySmtpAddress
End If
End If
Else
If obj.SenderEmailAddress = "" Then
strSender = "ERROR@ERROR.GOV"
Else
MsgBox obj.SenderEmailAddress
'MsgBox obj.PrimarySmtpAddress 'errs out
'MsgBox Sender.GetExchangeUser() 'errs out
'MsgBox Obj.Sender.GetExchangeUser() 'errs out
strSender = obj.PrimarySmtpAddress
End If
End If
///Next
代码有效,但适用于来自电子邮件组(例如 helpdesk@myexchange.org)或伪造电子邮件地址的人.
The code works but for those coming from an email group (helpdesk@myexchange.org for example) or spoofed email addresses.
obj.SenderEmailAddress 结果为/O=EXCHANGELABS/OU=EXCHANGE ADMINISTRATIVE GROUP (removedtextforstack)/CN=RECIPIENTS/CN=7E2removedtextforstackF6-USERNAME"
obj.SenderEmailAddress results in "/O=EXCHANGELABS/OU=EXCHANGE ADMINISTRATIVE GROUP (removedtextforstack)/CN=RECIPIENTS/CN=7E2removedtextforstackF6-USERNAME"
我相信这是意料之中的,但是 Sender.GetExchangeUser() 给出了一个 Object Required 错误.我并不特别想要 3000 行代码来挖掘 AD 来尝试为每封电子邮件查找 AD 代码/用户.我们使用 Office 365,它由很多人管理,因此访问地址列表并不容易.
I believe this is to be expected, but Sender.GetExchangeUser() gives an Object Required error. I don't particularly want 3000 lines of code to dig through AD to try to look up an AD code/user for every email. We use office 365 and it's managed by many people, so things aren't straitforward with accessing the address lists.
推荐答案
MailItem.Sender.GetExchnageUser().ProimarySmtpAddress
对于 EX 发件人应该可以正常工作,但您的代码会检查 SenderEmailAddress
属性而不是 SenderEmailType
.改成
MailItem.Sender.GetExchnageUser().ProimarySmtpAddress
should work fine for the EX senders, but your code checks the SenderEmailAddress
property instead of SenderEmailType
. Change it to
If obj.SenderEmailType = "EX" Then
您还可以检查 PR_SENT_REPRESENTING_SMTP_ADDRESS 属性(DASL 名称 http://schemas.microsoft.com/mapi/proptag/0x5D02001F
,使用 MailItem.PropertyAccessor.GetProperty
)在使用 MailItem.Sender 属性之前(这是更昂贵的)
You can also check the PR_SENT_REPRESENTING_SMTP_ADDRESS property (DASL name http://schemas.microsoft.com/mapi/proptag/0x5D02001F
, use MailItem.PropertyAccessor.GetProperty
) before using the MailItem.Sender property (which is more expensive)
这篇关于在邮件的“发件人"字段中从 Exchange 用户中提取 SMTP 地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!