AttachmentSavedAs Property |
Namespace: MailBee.Mime
This property is especially useful when the attachment was saved to disk implicitly (for instance, when all embedded pictures/files referenced in the HTML body were saved to disk by GetHtmlAndSaveRelatedFiles method call, and the developer wants to know the exact paths to the saved files).
Filenames of such files depend on the way they were saved. Usually attachments are saved under the path specified by the developer if saving was explicit (e.g. with Save(String, Boolean) method); or if saving was implicit (e.g. with GetHtmlAndSaveRelatedFiles method), attachments are saved to MailMessage.Parser.WorkingFolder.
This property can also be set by GetHtmlAndSaveRelatedFiles(String, VirtualMappingType, MessageFolderBehavior) and similar methods when mappingType was set to StaticInMemory (even though no actual files are saved by MailBee in this case). In that mode, it's your app's responsibility to make sure the file is accessible via SavedAs path when being accessed via web.
If mappingType was set to Base64 (so that GetHtmlAndSaveRelatedFiles(String, VirtualMappingType, MessageFolderBehavior) method embedded the attachment contents right into the HTML body), this property won't be set and will remain an empty string.
// To use the code below, import MailBee namespaces at the top of your code. using MailBee; using MailBee.Mime; // The actual code (put it into a method of your class) // Load the message from file. MailMessage msg = new MailMessage(); msg.LoadMessage(@"C:\Docs\TestMail.eml"); // For every attachment... foreach (Attachment attach in msg.Attachments) { // ...save the attachment into the specified folder overwriting the existing file if necessary, attach.SaveToFolder(@"C:\Temp\", true); // and show the full path to the saved file. Console.WriteLine("The path is " + attach.SavedAs); }