user1453442
user1453442

Reputation: 43

Outlook 2010 - C# - Get the account associated to a mail

I'm creating an Outlook add-in that can save selected emails to an external database.

Using the Office.IRibbonControl I can get the list of the selected email, but I need to know to which account those mails are associated.

I mean, if Outlook get messages from [email protected] and from [email protected], when I want to save a message I need to know that information.

I can't use the informations like sender / receiver because it can be an outcome like an income email.

Currently, the only I have found is using the current folder path..

public void SayHello(Office.IRibbonControl control)
{
    MessageBox.Show(
        "Folder: " + (control.Context as Outlook.Explorer).CurrentFolder.FolderPath,
        "Test",
        MessageBoxButtons.OK,
        MessageBoxIcon.Information);
}

But the method isn't good enough. If I open a message (in a separated window) and then I change the current folder, it fails.

Also, Outlook.Explorer.CurrentAccount does not work as I expected.

So here is my question : How can I access the related account having a Outlook.MailItem object ?

Upvotes: 4

Views: 1712

Answers (1)

SliverNinja - MSFT
SliverNinja - MSFT

Reputation: 31641

You can get the parent folder (MailItem.Parent) of an Outlook.MailItem to determine its Folder path (Folder.FolderPath).

Outlook.Folder parent = MailItem.Parent as Outlook.Folder;
string itemPath = parent.FolderPath;

Upvotes: 4

Related Questions