SenderEmailAddress 属性不包含内部联系人的标准电子邮件地址
背景:
使用 Outlook 规则触发脚本,我希望收到来自某些高可见性客户的所有电子邮件后立即打开.
Using an Outlook Rule to trigger a script, I want all of my email from certain high-visibility clients to open immediately upon receipt.
我已成功设置了一个规则,当这些客户向我发送电子邮件时会触发该规则.它看起来像这样:
I have successfully set up a rule that triggers when those clients send me email. It looks something like this:
并且我已经成功创建了一个脚本来打开对电子邮件的回复,具体取决于发送者.它看起来像这样:
And I have successfully created a script that opens a reply to the email, depending on who sent it. It looks something like this:
Sub OpenEmailImmediately(oEmail As Outlook.MailItem)
Select Case oEmail.Sender
Case "Jobs, Steve"
oEmail.Reply.Display
End Select
End Sub
虽然这有效,但我已经使用 .Sender
属性实现了它.
Although this works, I have implemented it using .Sender
property.
问题:
我更喜欢使用发件人的电子邮件地址(与我收到的每封电子邮件相关联的唯一值)来实现这一点.不幸的是,oEmail.SenderEmailAddress
,我希望它包含电子邮件地址,只适用于外部客户.
I would prefer to implement this using the sender's email address (a unique value associated with every email I receive). Unfortunately, oEmail.SenderEmailAddress
, which I expected to contain the email address, only worked for external clients.
在进行故障排除时,我发现我期望 oEmail.SenderEmailAddress
的值与此类似:
While troubleshooting, I discovered that where I expected oEmail.SenderEmailAddress
to have a value similar to this:
steve.jobs@apple.com
steve.jobs@apple.com
对于内部电子邮件,它的值类似于:
for internal emails it had a value similar to this:
/O=APPLE/CN=RECIPIENTS/CN=JOBSS6738
/O=APPLE/CN=RECIPIENTS/CN=JOBSS6738
问题:
有什么方法可以使这个脚本适用于使用标准电子邮件地址的内部和外部人员?
Is there a way I can make this script work for internals and externals using their standard email address?
已实施解决方案的代码:
使用下面 Dmitry 的回答,将代码修改为使用电子邮件地址:
Using Dmitry's answer below, the code was modified to use the email address:
Sub OpenEmailImmediately(oEmail As Outlook.MailItem)
If oEmail.SenderEmailType = "EX" Then
Select Case oEmail.Sender.GetExchangeUser().PrimarySmtpAddress
Case "steve.jobs@apple.com"
oEmail.Reply.Display
End Select
Else
Select Case oEmail.SenderEmailAddress
Case "tom.brady@patriots.com"
oEmail.Reply.Display
End Select
End If
End Sub
这是一个完全有效的EX"类型地址(与 SMTP 相对) - 检查 MailItem.SenderEmailType
的值财产.如果是SMTP",请使用MailItem.SenderEmailAddress
.如果是EX",使用MailItem.Sender.GetExchangeUser().PrimarySmtpAddress
.
This is a perfectly valid address of type "EX" (as opposed to SMTP) - check the value of the MailItem.SenderEmailType
property. If it is "SMTP", use MailItem.SenderEmailAddress
. If it is "EX", use MailItem.Sender.GetExchangeUser().PrimarySmtpAddress
.
您也可以尝试使用 MailItem 读取
- 查看带有 OutlookSpy 的消息(单击 IMessage 按钮) 或 MFCMAPI.PidTagSenderSmtpAddress
MAPI 属性(DASL 名称 http://schemas.microsoft.com/mapi/proptag/0x5D01001F
).PropertyAccessor.GetProperty
You can also try to read PidTagSenderSmtpAddress
MAPI property (DASL name http://schemas.microsoft.com/mapi/proptag/0x5D01001F
) using MailItem.PropertyAccessor.GetProperty
- take a look at the message with OutlookSpy (click IMessage button) or MFCMAPI.