从 Outlook.MailItem 获取发件人返回 null

发布于 2025-01-17 20:44:20 字数 396 浏览 2 评论 0原文

我试图获取 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

毁我热情 2025-01-24 20:44:21

请记住,与发件人相关的属性仅在接收到的消息上填充。如果要在提交的消息上访问这些属性,则在发送消息并将其移至已发送项目文件夹之前,它们才会存在。

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.

徒留西风 2025-01-24 20:44:21

您可以查看 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 a Recipient object.

〆一缕阳光ご 2025-01-24 20:44:21

假设您有一个outlook.mailitem,则不是null,则应该能够遵循此过程来检索发件人的电子邮件地址,从

string PR_SMTP_ADDRESS = @"http://schemas.microsoft.com/mapi/proptag/0x39FE001E";

if (omi == null)
{
    throw new ArgumentNullException();
}
if (omi.SenderEmailType == "EX")
{
    Outlook.AddressEntry sender = omi.Sender;
    
    if (sender != null)
    {
        // Now we have an AddressEntry representing the Sender
        if (sender.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeUserAddressEntry ||
            sender.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeRemoteUserAddressEntry)
        {
            // Use the ExchangeUser object PrimarySMTPAddress
            Outlook.ExchangeUser exchUser = sender.GetExchangeUser();
            
            if (exchUser != null)
            {
                return exchUser.PrimarySmtpAddress;
            }
            else
            {
                return null;
            }
        }
        else
        {
            return sender.PropertyAccessor.GetProperty(PR_SMTP_ADDRESS) as string;
        }
    }
    else
    {
        return null;
    }
}
else
{
    return omi.SenderEmailAddress;
}

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.

string PR_SMTP_ADDRESS = @"http://schemas.microsoft.com/mapi/proptag/0x39FE001E";

if (omi == null)
{
    throw new ArgumentNullException();
}
if (omi.SenderEmailType == "EX")
{
    Outlook.AddressEntry sender = omi.Sender;
    
    if (sender != null)
    {
        // Now we have an AddressEntry representing the Sender
        if (sender.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeUserAddressEntry ||
            sender.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeRemoteUserAddressEntry)
        {
            // Use the ExchangeUser object PrimarySMTPAddress
            Outlook.ExchangeUser exchUser = sender.GetExchangeUser();
            
            if (exchUser != null)
            {
                return exchUser.PrimarySmtpAddress;
            }
            else
            {
                return null;
            }
        }
        else
        {
            return sender.PropertyAccessor.GetProperty(PR_SMTP_ADDRESS) as string;
        }
    }
    else
    {
        return null;
    }
}
else
{
    return omi.SenderEmailAddress;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文