0

I am having problems attempting to retrieve the default inbox folder because I have no instance to retrieve it from.

Ultimately, I'm attempting to retrieve a list of mail items that are one year or more old, such that I can display these mails in a form and let a user know these mails are about to expire so either move them, save them, or it will be deleted. There is a new corporate e-mail rentention policy that deletes emails after one year and doesn't let users know.

Before I can do that however, I need a list of MailItems. When outlook begins, outlook calls the following code:

/// <summary>
/// Overridden method to allow Outlook to look for and load extensions.
/// </summary>
/// <returns>A <see cref="MailExpiryAlert"/> class containing the extension logic</returns>
protected override Office.IRibbonExtensibility CreateRibbonExtensibilityObject()
{
    if (Application.Explorers.Count > 0)
    {
        string breakPoint = "this break point will never be reached on initial startup";
    }
    return new MailExpiryAlert();
}

However, I get the following error: NullReferenceExceptoin: Object reference not set to an instance of an object. This is because the Explorer window hasn't loaded yet, and therefore is null. However, how am I supposed to load my extension (it depends on the explorer and folders within) before outlook itself loads? I know I'm missing something very elementary here but any help would be greatly appreciated.

Magnum
  • 1,555
  • 4
  • 18
  • 39

1 Answers1

1

You need Application.Session.GetDefaultFolder(olFolderInbox), it does not matter whether there are active explorers or not.

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78