keni zhou
Guest
|
Dear Andrei,
I have a Outlook profile with more than one email accounts, for example:
user1@dev.test.gov
|-inbox
|-Drafts
|-Sent Items
|.....
user2@dev.test.gov
|-inbox red
|-Drafts
|-Sent Items
|.....
I would like to get the smtp address "user2@dev.test.gov" when I select the "inbox" folder of user2. Here is the code to get the smtp address. but it randomly get the "The operation failed, cannot find object, System.Runtime.InteropServices.COMException (0xBDD4010F):" error when try to get storeId "Microsoft.Office.Interop.Outlook.MAPIFolder.get_StoreID()":
public static Account CurrentAccount
{
get
{
try
{
var currentFolder = CurrentFolder;
if (currentFolder != null)
{
string storeId = currentFolder.StoreID;
currentFolder.ReleaseComObject();
var accounts = ThisAddIn.Application.Session.Accounts;
foreach (Account item in accounts)
{
using (var deliveryStore = item.DeliveryStore.WithComCleanup())
{
if (deliveryStore.Resource.StoreID == storeId)
{
currentFolder.ReleaseComObject();
accounts.ReleaseComObject();
return item;
}
}
item.ReleaseComObject();
}
accounts.ReleaseComObject();
}
}
catch (System.Exception ex)
{
ExceptionHandler.SupressException(ex);
}
return null;
}
}
Do you have any idea on this? Thank you very much! |
|
Andrei Smolin
Add-in Express team
Posts: 18830
Joined: 2006-05-11
|
Hello Keni,
Wrap that statement in a try/catch. When the exception occurs, study the properties of the currentFolder. Can it be that that folder is a calendar folder of another user? Is the folder name that the currentFolder returns meaningful?
keni zhou writes:
foreach (Account item in accounts)
Replace foreach with the for loop. foreach creates and doesn't release a COM object internally.
Andrei Smolin
Add-in Express Team Leader |
|