Microsoft.Office.Interop.Outlook.MailItem 不包含发件人的定义

本文关键字:定义 包含发 Office Interop Outlook MailItem Microsoft | 更新日期: 2023-09-27 18:32:33

我正在尝试使用msdn中的以下代码示例:

private string GetSenderSMTPAddress(Outlook.MailItem mail)
{
    string PR_SMTP_ADDRESS = @"http://schemas.microsoft.com/mapi/proptag/0x39FE001E";
    if (mail == null)
    {
        throw new ArgumentNullException();
    }
    if (mail.SenderEmailType == "EX")
    {
        //This rows gives an error:
        //Microsoft.Office.Interop.Outlook.MailItem does not contain a definition for Sender
        Outlook.AddressEntry sender = mail.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();
                return (exchUser != null) ? exchUser.PrimarySmtpAddress : null;
            }
            return sender.PropertyAccessor.GetProperty(PR_SMTP_ADDRESS) as string;
        }
        return null;
    }
    return mail.SenderEmailAddress;
}

但是由于某种原因,我收到此编译错误:

'Microsoft.Office.Interop.Outlook.MailItem' does not contain a definition for 'Sender' 
and no extension method 'Sender' accepting a first argument of type 
'Microsoft.Office.Interop.Outlook.MailItem' could be found 
(are you missing a using directive or an assembly reference?)

我正在使用框架 3.5 的 winforms,我可以做...?

Microsoft.Office.Interop.Outlook.MailItem 不包含发件人的定义

请参阅操作方法:将基于 Exchange 的电子邮件地址转换为 SMTP 电子邮件地址。它支持早期的Outlook版本。

附言您可以通过在"解决方案资源管理器"窗口中选择它来检查 Outlook 互操作引用。在"属性"窗口中将找到其版本。