office-jsoutlook-addinoutlook-web-addinsaddin-express

Can I use an Outlook Add-In to save an email and also update a file on the users PC


I am trying to translate the below code to an Microsoft Add-In with a xml.manifest that can be uploaded to the cloud and will be downloaded every time Outlook updates, as currently we have to re-add it to everyone's PC. We were using a COM-addin with Add-in Express, but wanted to get away from that. The final product needs to save the email with the name 'email-import.msg' in a certain folder "C:\mgatemp\ user -zan" as well as update another file to indicate the email has been deposited there.

The below is for reference

            var msg = this.OutlookApp.ActiveExplorer().Selection[1];
            if (msg is Outlook.MailItem)
            {
                try
                {
                    string basepath = @"c:\mgatemp\";
                    Outlook.MailItem mailitem = (msg as Outlook.MailItem);
                    mailitem.SaveAs(basepath + user + "-zan" + @"\email-import.msg");
                    
                    FileStream myFileStream = File.Open(basepath + user + "-zan" + @"\sentinel.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
                    myFileStream.Close();
                    myFileStream.Dispose();


                    System.IO.File.SetLastWriteTimeUtc(basepath + user + "-zan" + @"\sentinel.txt", DateTime.UtcNow);


                     
                 }                  
                catch
                {
                    MessageBox.Show("could note write for user zan/sentinel" + user);

                }

Solution

  • JS based addins cannot save messages in the MSG format - the format is Windows Outlook specific (it is IStorage based) and is only accessible in the Outlook Object Model and Extended MAPI out of the box (both Windows only). JS also cannot access local file system.