If you add your attachments through the Attachment constructor with the filePath argument, these attachments can be obtained through the ContentStream property and will be of the FileStream type. Here's how you can get attachment file names:
var fileNames = message.Attachments .Select(a => a.ContentStream) .OfType<FileStream>() .Select(fs => fs.Name);
But remember to delete the MailMessage object MailMessage , otherwise you cannot delete these attachments:
IEnumerable<string> attachments = null; using (var message = new MailMessage()) { ... attachments = message.Attachments .Select(a => a.ContentStream) .OfType<FileStream>() .Select(fs => fs.Name); } foreach (var attachment in attachments ) { File.Delete(attachment); }
Alex May 6 '11 at 14:39 2011-05-06 14:39
source share