I've written an application that will read the emails in a given mailbox and save the attachments. Unfortunately, I've now been told that they will have to be saved to a network location on another domain.
Does anyone know how to achieve this? My current code is below, and it's the fileAttachment.Load(savedFileName); statement that does the saving.
Incidentally, I haven't tested this yet because I still haven't been given the mailbox credentials, so I'm not 100% certain that it will work as it is.Code:Log.Debug("Retrieving items from Inbox."); var theseItems = folder.FindItems(new ItemView(200)); foreach (Item outlookItem in theseItems) { if (outlookItem is EmailMessage) { var message = (EmailMessage)outlookItem; Log.Debug("Processing email " + message.Subject + " from " + message.Sender); foreach (Attachment attachment in message.Attachments) { if (attachment is FileAttachment) { FileAttachment fileAttachment = attachment as FileAttachment; if (fileAttachment.Name.EndsWith(".csv") || fileAttachment.Name.EndsWith(".xls")) { var savedFileName = destinationDirectory + fileAttachment.Name; Log.Debug("Saving file " + savedFileName); fileAttachment.Load(savedFileName); } } } } }




Reply With Quote