开发者

Is it possible to access the current MailItem on Ribbon_Load?

开发者 https://www.devze.com 2023-02-26 16:15 出处:网络
I have an Outlook ribbon of the following type: Microsoft.Outlook.Mail.Compose, Microsoft.Outlook.Mail.Read

I have an Outlook ribbon of the following type: Microsoft.Outlook.Mail.Compose, Microsoft.Outlook.Mail.Read

I need to enable or disable a button from this ribbon, based on the content (body) of the mail item, and I was thinking to do this on the ribbon's Load event.

I have the following code, but the ActiveInspector is always null.

    private vo开发者_如何学Cid RiverRaftRibbon_Load(object sender, RibbonUIEventArgs e)
    {
        var application = Globals.ThisAddIn.Application;
        var inspector = application.ActiveInspector();
        MailItem myMailItem = (MailItem)inspector.CurrentItem;

        string projectName;
        DateTime? dueDate;

        if (Common.ParserHelper.IsRiverRaftEmail(mail.HTMLBody, out projectName, out dueDate))
        {
            btnAccept.Enabled = true;
        }
        else
            btnAccept.Enabled = false;

    }

Thank you!


Try this:

var application = Globals.ThisAddIn.Application;
Outlook.Selection selection = application.ActiveExplorer().Selection;
                    mailItem = selection[1] as Outlook.MailItem;
0

精彩评论

暂无评论...
验证码 换一张
取 消