首页 > 解决方案 > 如何在发送前将 Outlook 邮件对象作为草稿电子邮件打开?

问题描述

void send_reply(Outlook.MailItem item, HashSet<string> names)
    {
        Outlook.MailItem eMail = item.Reply();
        // want to open an email draft box for user to type in the email's content then return to the program here
        eMail.Display();
        foreach (string s in names)
        {
            eMail.To = s;
            //MessageBox.Show("this is the guy we are sending to " + item.To);
            eMail.Importance = Outlook.OlImportance.olImportanceHigh;
            ((Outlook._MailItem)eMail).Send();

        }
    }

想要向给定的邮件项发送回复,但只发送到名称中指定的电子邮件地址。我遇到的问题是,当我调用 eMail.Display() 时,它最多只显示半秒钟,然后草稿自动关闭,我向每个人发送一封空白回复电子邮件。

有人有什么建议吗?

标签: c#outlookoutlook-addin

解决方案


Display()函数立即返回并使您发送的消息为空。

true您可以通过传递给函数来等待:

//...
  Outlook.MailItem eMail = item.Reply();
  eMail.Display(true); // <-- here
//...

这将使窗口模态并等待用户关闭它。

也许您还必须检查用户是否在没有文本的情况下关闭它或打算撤消操作......

为此,您可以检查消息状态或将处理程序注册到一个(或两个)Close(和Send)事件。


推荐阅读