0

I have a problem with development of a Office 365 Outlook Addin (Desktop). I need to modify certain properties on a MailItem opened with a custom form ( Form designed in Outlook, exported as OFS file and imported in to Visual Studio AddIn project) but the call of method 'Save' on MailItem object doesn't working, "Saved" property remain to "false" and when i close the inspector, Outlook prompt to save current item. No exception or error message raised on 'Save' call. But if i try to call 'Save' to the same MailItem in the AddIn body, the message is saved. I tried to write a simple test "addin" and i obtained the same result, but i can't understand this behaviour.

NB: with previous version of Outlook i haven't this issue. Any idea? Thanks so much!

Currently using VS2017, C#, .NET Framework 4.5, Interop library version 15.0


    // ADD-IN BODY

    private Outlook.Inspectors inspectors;
    public static MailItem CurrentMailItem;

    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {     
        inspectors = this.Application.Inspectors;
        inspectors.NewInspector += Inspectors_NewInspector;
    }

    private void Inspectors_NewInspector(Inspector Inspector)
    {

        if (Inspector.CurrentItem is MailItem)
        {
            MailItem item = (MailItem)Inspector.CurrentItem;

            item.MessageClass = "IPM.Note.MyReader";
            item.Save();
            bool saved = item.Saved;
            Marshal.ReleaseComObject(item);
            item = null;
        }
    }

    // CUSTOM FORM:

    private void FormRegion2_FormRegionShowing(object sender, System.EventArgs e)
    {
        // from this.OutlookItem
        MailItem item = this.OutlookItem as MailItem;
        item.Save();
        bool saved = item.Saved; // <== SAVED=FALSE!

        // from global variable (static)    
        ThisAddin.CurrentMailItem.Save();   
        saved = ThisAddin.CurrentMailItem.Saved; // <=== SAVED=FALSE!!!!
    }  
VxSimon
  • 1
  • 1

2 Answers2

0

It seems you are using wrong event NewInspector to modify the message class. Have a look at this thread

Victor Ivanidze
  • 397
  • 2
  • 7
  • Thanks, but this is not the real problem. The problem is the imported form created with Outlook 2013. I think there are compatibility problems in Outlook 2016 Form Designer. It's not clear why it's not possibile to save changes with that form, it's an incomprensibile behaviour. It's not possibile to save changes not only with the 'Save' method, but also with the menu item 'Save'. Then, I created a new form with Outlook 2016 and imported again in VS2017 and now it's "working" (not very well: it's not possibile to change some properties on form designer). I'm not sure on Office 2013.... – VxSimon Jan 14 '19 at 11:42
0

I think it's a problem with the specific custom form that i've created, or a compatibility problem with Outlook 2016 (the same form working with Outlook 2013)

Steps to the resolution:

It's not the definitive solution, because now i must recreate a form with Outlook 2016 and i'm not sure that it's working with previous version of Office. Moreover, the designer of Outlook 2016 have some problem with font size… i can't change font size to '8' for any label present in the form.

VxSimon
  • 1
  • 1