问题
Background:
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
Although this works, I have implemented it using .Sender
property.
Problem:
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.
While troubleshooting, I discovered that where I expected oEmail.SenderEmailAddress
to have a value similar to this:
steve.jobs@apple.com
for internal emails it had a value similar to this:
/O=APPLE/CN=RECIPIENTS/CN=JOBSS6738
Question:
Is there a way I can make this script work for internals and externals using their standard email address?
Code with implemented solution:
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
回答1:
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
.
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.
来源:https://stackoverflow.com/questions/36900156/senderemailaddress-property-does-not-contain-a-standard-email-address-for-intern