如何获取Outlook邮件的发件人 [英] How to get the sender of an outlook message
问题描述
我有一些代码可以部分填充电子邮件作为回复.但是,除非他们在(一个/我们)上,否则我无法获取发件人?交换服务器.
I have some code that partially populates an email message as a reply. But I can not get the sender unless they are on (an / our)? exchange server.
Public Sub CreateMessage()
Dim EmailFrom As String
Dim NewMessage As Outlook.MailItem
Dim OldMessage As Outlook.MailItem
Set OldMessage = Application.ActiveInspector.CurrentItem
Set NewMessage = Application.CreateItem(olMailItem)
EmailFrom = OldMessage.Sender.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x39FE001E")
NewMessage.Body = Body(EmailFrom)
NewMessage.HTMLBody = HTMLBody(EmailFrom)
NewMessage.Recipients.Add (EmailFrom)
NewMessage.Display
Set NewMessage = Nothing
End Sub
我收到的消息是属性" http://schemas.microsoft.com/mapi/proptag/0x39FE001E "未知或找不到."并且它似乎仅适用于内部消息.
The message I receive is "The property "http://schemas.microsoft.com/mapi/proptag/0x39FE001E" is unknown or cannot be found." and it only appears to work with internal messages.
任何人都知道Outlook VBA中的一种方法来获取对所有用户都适用的邮件发件人吗?
Anyone know of a way in Outlook VBA to get the sender of a mail message that works for all of them?
根据Dimitry的评论修正:
Fixed based on Dimitry's comments:
Public Sub CreateMessage()
Dim EmailFrom As String
Dim NewMessage As Outlook.MailItem
Dim OldMessage As Outlook.MailItem
Set OldMessage = Application.ActiveInspector.CurrentItem
Set NewMessage = Application.CreateItem(olMailItem)
Select Case OldMessage.SenderEmailType
Case "EX"
EmailFrom = OldMessage.Sender.GetExchangeUser.PrimarySmtpAddress
Case Else
EmailFrom = OldMessage.SenderEmailAddress
End Select
NewMessage.Body = Body(EmailFrom)
NewMessage.HTMLBody = HTMLBody(EmailFrom)
NewMessage.Recipients.Add (EmailFrom)
NewMessage.Display
Set NewMessage = Nothing
End Sub
推荐答案
您正在请求PR_SMTP_ADDRESS
属性,该属性是Exchange特有的.检查SenderEmailType
是否为"EX",然后才读取PR_SMTP_ADDRESS
属性.否则,只需阅读MailItem.SenderEmailAddress
属性.
You are requesting the PR_SMTP_ADDRESS
property, which is Exchange specific. Check if SenderEmailType
is "EX" and only then read the PR_SMTP_ADDRESS
property. Otherwise just read the MailItem.SenderEmailAddress
property.
使用 OutlookSpy (单击IMessage)查看消息,以查看可用的属性.
Take a look at the message with OutlookSpy (click IMessage) to see the available properties.
这篇关于如何获取Outlook邮件的发件人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!