none
VSTO-Task Pane get Current MailItem RRS feed

  • Question

  • I build a VSTO Outlook C# addin by this Link:

    (github)Walkthrough: Display custom task panes with email messages in Outlook(all right MSDN don't allow me insert link I think you can search on github,sorry[: (] )

    I insert a button on the task pane.

    Now I want to use this button to insert a mail titel like"tset for button"by action Button_Click

    I try to use 

    Outlook.Inspector inspector = Globals.ThisAddIn.Application.ActiveInspector();

    or

    Outlook.MailItem mailItem = Inspector.CurrentItem as Outlook.MailItem;

    to get current inspector but seems not work.

    Here is my code below:

    private void InsertButton_Click(object sender, EventArgs e)
            {
                Outlook.Inspector inspector = Globals.ThisAddIn.Application.ActiveInspector();
                if (inspector is Outlook.MailItem)
                {
                    public Outlook.MailItem mailItem;
                    mailItem = inspector as Outlook.MailItem;
                    mailItem.subject = "test for button";                
                }                               
            }

    And I also tried this founction:

    private void InsertButton_Click(object sender, EventArgs e)
            {
                Outlook.MailItem mailItem = Inspector.CurrentItem as Outlook.MailItem;
                mailItem.subject = "test for button";
            }

    Can you tell me what's wrong with me?



    Monday, April 1, 2019 1:12 PM

Answers

  • Hello,

    I follow your advice and send a issue on GitHub. Mr. John Hart answered my question.

    Here is his code below:

    private void Button1_Click(object sender, EventArgs e)
        {
            Inspector inspector = Globals.ThisAddIn.Application.ActiveInspector();
            MailItem mailItem = inspector.CurrentItem as MailItem;
            mailItem.Subject = "test for button";
        }

    Origin answer see the issue on GitHub: VSTO Outlook-Task Pane get Current MailItem

    Thursday, April 4, 2019 2:50 AM

All replies

  • Hello,

    All GitHub repositories have an "Issues" tab which is where you discuss the repo code and issues, try this and if no joy post in the Outlook for developers forum.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Monday, April 1, 2019 1:42 PM
  • Thank you for your advice,I'll try it
    Tuesday, April 2, 2019 10:20 AM
  • Hello,

    I follow your advice and send a issue on GitHub. Mr. John Hart answered my question.

    Here is his code below:

    private void Button1_Click(object sender, EventArgs e)
        {
            Inspector inspector = Globals.ThisAddIn.Application.ActiveInspector();
            MailItem mailItem = inspector.CurrentItem as MailItem;
            mailItem.Subject = "test for button";
        }

    Origin answer see the issue on GitHub: VSTO Outlook-Task Pane get Current MailItem

    Thursday, April 4, 2019 2:50 AM