在 Outlook Interop 中检索电子邮件发件人时出现问题

问题描述 投票:0回答:1

我们正在开发一个 Outlook 365 插件,用于检索电子邮件的各个部分以创建文件。 当收件箱中的邮件通过 Exchange 发送时,我们无法检索发件人。我们复制了微软手册页中的一个方法,但它总是返回 null。

方法是这样的:

        private string GetSenderSMTPAddress(Microsoft.Office.Interop.Outlook.MailItem mail)
    {
        string PR_SMTP_ADDRESS =
            @"http://schemas.microsoft.com/mapi/proptag/0x39FE001E";
        if (mail == null)
        {
            throw new ArgumentNullException();
        }
        if (mail.SenderEmailType == "EX")
        {
            Microsoft.Office.Interop.Outlook.AddressEntry sender =
                mail.Sender;
            if (sender != null)
            {
                //Now we have an AddressEntry representing the Sender
                if (sender.AddressEntryUserType ==
                    Microsoft.Office.Interop.Outlook.OlAddressEntryUserType.
                    olExchangeUserAddressEntry
                    || sender.AddressEntryUserType ==
                    Microsoft.Office.Interop.Outlook.OlAddressEntryUserType.
                    olExchangeRemoteUserAddressEntry)
                {
                    //Use the ExchangeUser object PrimarySMTPAddress
                    Microsoft.Office.Interop.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 mail.SenderEmailAddress;
        }
    }

我们可以做什么来找回发件人?该手册页似乎已过时

c# outlook office365 office-interop com-interop
1个回答
0
投票

发件人相关属性仅在电子邮件发送后设置。确保您在 Outlook 中处理发送或接收的项目。为此,您可以检查

MessageFlags
标志的
MSGFLAG_UNSENT
位掩码。

© www.soinside.com 2019 - 2024. All rights reserved.