C#; Outlook AddIn; Replace Attachment

Jul 16, 2013 at 2:33 PM
Hallo guys,

I wrote an AddIn, which take the NewMailExEvent to get informed about new emails.

Then the AddIn saves the attachments as files and should replace the original attachment with just a link to the saved one.

I am deleting the old attachments and adding just a string (the path to the saved one). But it seems that outlook not just takes the path but also the whole data and put it into the email.

I checked the size of the "sniffed" email and its the exact size of the "not sniffed" email.

            var newMail = (Outlook.MailItem)outlookApp.Session.GetItemFromID(EntryIDCollection, Missing.Value);

            List<string> paths = new List<string>();

            for(int i = newMail.Attachments.Count; i >= 1; i--) {
                string _base = @"basepath...\";
                string name = newMail.ReceivedByName.Replace(',', '_').Replace(" ", "");
                string subname = newMail.SenderName.Replace(',', '_').Replace(" ", "");

                if(!Directory.Exists(_base + "files")) {
                    Directory.CreateDirectory(_base + "files");
                }

                if(!Directory.Exists(_base + "files\\" + name)) {
                    Directory.CreateDirectory(_base + "files\\" + name);
                }

                if(!Directory.Exists(_base + "files\\" + name + "\\" + subname)) {
                    Directory.CreateDirectory(_base + "files\\" + name + "\\" + subname);
                }
                
                string path = _base + "files\\" + name + "\\" + subname + "\\" + newMail.Attachments[i].FileName;

                Outlook.Attachment oldAtt = newMail.Attachments[i];

                paths.Add(path);

                oldAtt.SaveAsFile(path);
                oldAtt.Delete();
            }

            for(int i = 0; i < paths.Count; i++) {
                newMail.Attachments.Add(paths[i]);
            }
Is it even possible to just insert a path?

greetings