Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 如何获取outlook邮件的发件人_Vba_Email_Outlook - Fatal编程技术网

Vba 如何获取outlook邮件的发件人

Vba 如何获取outlook邮件的发件人,vba,email,outlook,Vba,Email,Outlook,我有一些代码,部分填充电子邮件作为回复。但是我不能得到寄件人,除非他们在(我们的)?exchange服务器 Public Sub CreateMessage() Dim EmailFrom As String Dim NewMessage As Outlook.MailItem Dim OldMessage As Outlook.MailItem Set OldMessage = Application.ActiveInspector.CurrentItem Set NewMessage

我有一些代码,部分填充电子邮件作为回复。但是我不能得到寄件人,除非他们在(我们的)?exchange服务器

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
我收到的消息是“属性”“未知或找不到”。并且它似乎仅适用于内部消息

有人知道在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

您正在请求特定于Exchange的
PR\u SMTP\u ADDRESS
属性。检查
SenderEmailType
是否为“EX”,然后读取
PR\u SMTP\u ADDRESS
属性。否则,只需读取
MailItem.SenderEmailAddress
属性


使用(单击IMessage)查看消息以查看可用属性

真不敢相信我错过了!谢谢在Exchange的情况下,您可能希望改用MailItem、Sender.GetExchangeUser.PrimarySmtpAddress(当然要检查空值)-PR_SMTP_地址不保证可用。只是想说明我需要检查SenderEmailType。如果类型是“EX”,那么我必须使用我发布的代码,否则Dmitry的解决方案将非常有效。