我正在尝试使用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,我可以做吗??
答案 0 :(得分:0)
见HowTo: Convert Exchange-based email address into SMTP email address。它支持早期的Outlook版本。
P.S。您可以通过在“解决方案资源管理器”窗口中选择它来检查Outlook互操作引用。在“属性”窗口中将找到其版本。