从 Outlook.MailItem 获取发件人返回 null
我试图获取 Outlook.MailItem 的发件人(发件人),但没有成功。它返回空值。
我在下面尝试过。
尝试 1:
string from = omi.SenderEmailAddress;
尝试 2:
var exch = omi.Sender.GetExchangeUser(); // it returns null
if (exch != null)
{
string from = exch.PrimarySmtpAddress;
}
我还检查了 omi.SenderEmailType 以查看类型是什么,它返回 null。
注意:omi 是 Outlook.MailItem 对象。
I am trying to get the sender (From) of an Outlook.MailItem without success. It returns null.
I have tried below.
Attempt 1:
string from = omi.SenderEmailAddress;
Attempt 2:
var exch = omi.Sender.GetExchangeUser(); // it returns null
if (exch != null)
{
string from = exch.PrimarySmtpAddress;
}
Also I have checked omi.SenderEmailType to see what type is, and it returns null.
Note: omi is an Outlook.MailItem object.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请记住,与发件人相关的属性仅在接收到的消息上填充。如果要在提交的消息上访问这些属性,则在发送消息并将其移至已发送项目文件夹之前,它们才会存在。
Keep in mind that the sender related properties are only populated on the received or already sent messages. If you are accessing these properties on a message being submitted, they won't be present until the message is sent and moved to the Sent Items folder.
您可以查看
SendUsingAccount
属性。如果未设置,则可以使用 命名空间。 CurrentUser 属性,以Recipient
对象的形式返回当前登录用户的显示名称。You can check out the
SendUsingAccount
property. If it is not set then you can use the Namespace.CurrentUser property which returns the display name of the currently logged-on user as aRecipient
object.假设您有一个outlook.mailitem,则不是null,则应该能够遵循此过程来检索发件人的电子邮件地址,从
Assuming you have an Outlook.MailItem that is not null, you should be able to follow this process to retrieve the sender's email address, adapted from the Microsoft Documentation.