Outlook的发布控制

时间:2014-01-28 01:15:01

标签: c# outlook office-interop

我有一个使用Office Interop的应用程序,它启动Outlook,创建一个电子邮件并附加一个文件。我的问题是,在发送/关闭电子邮件之前,程序不会继续处理。我如何发布它,所以一旦下面的代码运行,其余的代码将继续,而最终用户修改电子邮件?是否像在不同的线程中运行代码一样简单,还是有更好的方法?

 if (!Common.IsOutlookRunning())
            Process.Start("OUTLOOK.EXE");
        var outlook = new Outlook.Application();
        var message = (Outlook.MailItem)outlook.CreateItem(Outlook.OlItemType.olMailItem);
        message.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;
        var recipients = (Outlook.Recipients)message.Recipients;
        var recipient = (Outlook.Recipient)recipients.Add(hire.Email);
        message.HTMLBody = "<p style=\"font-size:9.0pt;font-family:Verdana,sans-serif;color:#000066\">" +
        "Dear " + hire.ClientName + ",<br><br>";
        message.HTMLBody += "Please see the attached document. If you have any queries, please feel free to give me a call or send me an email.";
        var position = (int)message.HTMLBody.Length + 1;
        const int attachType = (int)Outlook.OlAttachmentType.olByValue;
        const string attachmentName = "Hire Docket";
        message.Attachments.Add(path, attachType, position, attachmentName);
        message.Subject = hire.Quote ? "Hire Quote" : "Hire Docket";
        message.BCC = "email@email.com";
        message.HTMLBody += "</p>" + Common.ReadSignature();
        recipient.Resolve();
        message.Display(true);

1 个答案:

答案 0 :(得分:1)

为了解决这个问题,我让它在另一个线程中运行,并让主线程做其他事情。

var thread = new Thread(() => Method(Parameters));
thread.Start();