2012-08-14 63 views
3

我試圖讓SMTP地址收到一封電子郵件,我寫了一個代碼以避免獲得x.500地址。我通過訪問PropertyAccessor.GetProperty(PR_SMTP_ADDRESS)獲取SMTP地址,其中PR_SMTP_ADDRESS = @"http://schemas.microsoft.com/mapi/proptag/0x39FE001E";Outlook加載項屬性錯誤

然而,這適用於一些筆記本電腦,而一些給一個錯誤,說

「的屬性http://schemas.microsoft.com/mapi/proptag/0x39FE001E不明或無法找到。」

任何想法如何解決這個問題?

回答

2

如果你想SMTP地址,您可以創建從X.500的Outlook.Recipient和解決Recipient.AddressEntryOutlook.ExchangeUser

string address = string.Empty; 
Outlook.Recipient recipient = mailItem.Application.Session.CreateRecipient(mailItem.SenderEmailAddress); 
if (recipient != null && recipient.Resolve() && recipient.AddressEntry != null) 
{ 
    Outlook.ExchangeUser exUser = recipient.AddressEntry.GetExchangeUser(); 
    if (exUser != null && !string.IsNullOrEmpty(exUser.PrimarySmtpAddress)) 
     address = exUser.PrimarySmtpAddress; 
} 

你與PR_SMTP_ADDRESS接收所述錯誤指示MIME屬性不存在於所述郵件消息屬性和需要的替代方法來確定發送者SMTP地址。您不能假定MIME屬性將始終存在。

+0

感謝SilverNinja,我應該訪問哪些屬性以獲取if語句中每個其他場景的電子郵件地址。 – amey1908 2012-08-14 19:29:18

+0

我使用了上面的代碼,它適用於某些Outlook帳戶,但不適用於其他帳戶。對於帳戶它不起作用,recipient.resolve()來作爲false。不知道爲什麼。我檢查了電子郵件地址,並以x.500格式顯示,並按照上面的代碼將其轉換爲primarysmtpaddress,但在recipient.resolve()時失敗。 – amey1908 2012-08-14 19:52:21

+0

**檢查名稱**是否適用於用戶名? ['Recipient.Resolve'](http://msdn.microsoft.com/en-us/librarY/microsoft.office.interop.outlook.recipient.resolve)只是針對用戶地址簿解析收件人。如果無法解析,則不會找到「AddressEntry」。作爲回退,您可以檢查屬性['PidLidInternetAccountName'](http://msdn.microsoft.com/zh-cn/library/ee202850%28v=exchg.80%29.aspx)是否存在。 – SliverNinja 2012-08-14 20:31:11