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

226 Views Asked by At

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);

                }
2

There are 2 best solutions below

2
On BEST ANSWER

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.

0
On

That's not possible. You may think about changing the implementation of your add-in a bit. Outlook web add-ins are run under the context of the currently selected item in Outlook (item's context) and don't have full access to the filesystem. Typically web applications are run in the sandboxed environment where the file IO operations are performed on the browser's cache folder.