none
Outlook C# VSTO Add-in - Attach Opened Message to New Message RRS feed

  • Question

  • I'm trying to use a button in the Read Message Inspector to attach an opened message to a new message, send it, and then delete it.  I have the following code in place, but it's not working.  I'm guessing I have to somehow relate the opened message to an item in the ActiveExplorer?  Or am I missing something simple in the construct I have below?

    public void SubmitOpenedMessage()

    {

       Outlook.Inspector activeInspector = this.Application.ActiveInspector();

       Outlook.Selection currentSelection = activeInspector.CurrentItem;

               

       DialogResult dialogResult = MessageBox.Show(

       "This message will be submitted to the proper mailbox for processing. Proceed?",

       "Submit Message?",

       MessageBoxButtons.YesNo);

               

       if (dialogResult == DialogResult.Yes)

         {

           //The opened message is cast and then is attached to a new message, which will be sent to the

           //proper mailbox with the opened item attached.  The opened message is then deleted.

                   

           Outlook.MailItem reportedItem;

           reportedItem = (Outlook.MailItem)currentSelection;

           Outlook.MailItem submission = Application.CreateItem(Outlook.OlItemType.olMailItem);

           foreach (string recipient in mailRecipients)

             {

               submission.Recipients.Add(recipient);

             }

           submission.Subject = mailSubjectPrefix + reportedItem.Subject;

           submission.Attachments.Add(reportedItem, Outlook.OlAttachmentType.olEmbeddeditem);

           submission.Body = mailBody;

           submission.Send();

           reportedItem.Delete();

         }

    }

    Tuesday, May 16, 2017 8:53 PM

All replies

  • Hi Mr. Jiggy,

    you had mentioned that,"I'm trying to use a button in the Read Message Inspector to attach an opened message to a new message"

    where you added this button?

    in the ribbon? or somewhere else.

    did you get any error while you run this code.

    if yes then let me know about the error message.

    it is helpful for us to understand the issue better.

    other thing I find in your above example is that you did not declare the "mailRecipients" in loop.

    you did not declare "mailSubjectPrefix" when you try to concatenate the subject.

    I did not find the declaration of "mailBody".

    so it is possible that you did not posted the full code or you did not declare that in your code.

    if you did not declare that then you need to declare it and assign value to it.

    Regards

    Deepak





    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, May 17, 2017 7:24 AM
    Moderator
  • Hey Deepak,

    The button is in the built-in Ribbon within its own Button Group.  There is no error message when the button is clicked; it simply doesn't do anything.

    The values for the variables used are declared within the context of the application but prior to construct of this function.  I have another function in the same context that makes use of them, and that is working correctly when executed from the separate button that exists on the Outlook Ribbon (also in its own Button Group on the built-in TabMail Ribbon.

    Wednesday, May 17, 2017 5:01 PM
  • Hi Mr. Jiggy,

    you had mentioned that,"The button is in the built-in Ribbon within its own Button Group.  There is no error message when the button is clicked; it simply doesn't do anything."

    did you try to debug the click event of button? is it execute the correct code?

    if you did not check that then try to check that first.

    other thing you had mentioned that," I have another function in the same context that makes use of them, and that is working correctly when executed from the separate button that exists on the Outlook Ribbon (also in its own Button Group on the built-in TabMail Ribbon."

    did you check that this function get correct values when you it?

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, May 19, 2017 5:59 AM
    Moderator