using MimeKit; using System; using System.IO; namespace wispro.sp.winClient { public class emlFileReader { private string _filePath; public emlFileReader(string filePath) { _filePath = filePath; using (var stream = File.OpenRead(_filePath)) { var message = MimeMessage.Load(stream); // 遍历所有附件 foreach (var attachment in message.Attachments) { if (attachment is MimePart part && part.IsAttachment) { string fileName = part.FileName; string contentType = part.ContentType.ToString(); // 保存附件到文件系统 string savePath = Path.Combine(Directory.GetCurrentDirectory(), fileName); using (var output = File.Create(savePath)) { part.Content.DecodeTo(output); } Console.WriteLine($"附件 '{fileName}' 已保存,类型: {contentType}"); } } } } } }