我有一些代码会将电子邮件部分填充为回复。但我不能得到发件人,除非他们在(我们/我们)?交换服务器。
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“未知或无法找到。”它似乎只适用于内部消息。
任何人都知道在Outlook VBA中获取适用于所有这些邮件的邮件发件人的方法吗?
根据Dimitry的评论修正:
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
答案 0 :(得分:3)
您正在请求PR_SMTP_ADDRESS
属性,该属性是特定于Exchange的。检查SenderEmailType
是否为" EX"然后才读取PR_SMTP_ADDRESS
属性。否则,只需阅读MailItem.SenderEmailAddress
属性。
使用OutlookSpy(单击IMessage)查看消息以查看可用属性。