public static void ReplyTo(MailMessage message, string body, List <string> attachments, bool replyAll, CancellationToken ct) { Application application = null; MailItem mailItem = null; MailItem mailItem2 = null; ct.ThrowIfCancellationRequested(); application = InitOutlook(); using (application.DisposeWithReleaseComObject()) { NameSpace @namespace = application.GetNamespace("MAPI"); string text = message.Headers["Uid"]; if (string.IsNullOrEmpty(text)) { throw new ArgumentException("非法的邮件对象!"); } mailItem = (dynamic)@namespace.GetItemFromID(text, Type.Missing); using (mailItem.DisposeWithReleaseComObject()) { mailItem2 = (replyAll ? mailItem.ReplyAll() : mailItem.Reply()); } using (mailItem2.DisposeWithReleaseComObject()) { foreach (string attachment in attachments) { ct.ThrowIfCancellationRequested(); mailItem2.Attachments.Add(attachment, Type.Missing, Type.Missing, Type.Missing); } mailItem2.HTMLBody = body + mailItem2.HTMLBody; mailItem2.BodyFormat = OlBodyFormat.olFormatHTML; ct.ThrowIfCancellationRequested(); mailItem2.Send(); } } }