【问题标题】:Reply to an (open) outlook mail from an external program从外部程序回复(打开的)Outlook 邮件
【发布时间】:2016-08-16 13:53:21
【问题描述】:

在一个外部应用程序中,我想回复一封电子邮件(Outlook 是电子邮件客户端)。电子邮件已在计算机屏幕上打开。在回复中,我想插入在外部应用程序代码中生成的回复。除了让消息在单独的 Outlook 窗口中回复已打开的电子邮件之外,我还可以搜索特定的邮件,然后使用代码进行回复。

有什么想法可以在 Outlook 对象中寻找吗?任何代码示例(vb.net 或 c#)?

我已经知道如何通过代码从我的外部应用程序在 Outlook 中创建新电子邮件,但我不确定如何回复现有电子邮件。

【问题讨论】:

    标签: c# vb.net outlook


    【解决方案1】:

    使用Application.ActiveExplorer.CurrentItem访问当前打开的消息,然后调用MailItem.Reply获取回复的MailItem对象,修改其消息体(MailItem.Body),调用MailItem.Display显示给用户。

    【讨论】:

    • 感谢提示,我得到了我想要的东西。谢谢。
    【解决方案2】:

    Outlook 项目的Reply 方法从原始邮件中创建一个回复,预先发送给原始发件人。您只需要获取当前打开的电子邮件,对其调用回复方法并使用Send方法发送电子邮件。

    要在资源管理器窗口中获取当前显示的电子邮件,您需要使用 Explorer 类的 Selection 属性(请参阅 Application 类的 ActiveExplorer 函数)。对于 Inspector 窗口,您可以使用 Inspector 类的 CurrentItem 属性(参见 Application 类的 ActiveInspector 函数)。有关更多信息和 C# 示例代码,请参阅 How to: Programmatically Determine the Current Outlook Item

    Outlook.Inspector inspector = null;
    Outlook.MailItem sourceMail = null;
    Outlook.MailItem replyMail = null;
    try
    {
        inspector =  Application.ActiveInspector();
        sourceMail = inspector.CurrentItem as MailItem;
        replyMail = sourceMail.Reply();
        // any modifications if required    
        replyMail.Send(); // just change mail to replyMail because mail variable ///is not declare 
    }
    catch (Exception ex)
    {
        System.Windows.Forms.MessageBox.Show(ex.Message,
            "An exception is occured in the code of add-in.");
    }
    finally
    {
        if (sourceMail != null) Marshal.ReleaseComObject(sourceMail);
        if (replyMail != null) Marshal.ReleaseComObject(replyMail);
        if (inspector != null) Marshal.ReleaseComObject(inspector);
    }
    

    您也可能会发现How To: Create and send an Outlook message programmatically 文章很有帮助。

    【讨论】:

    • 您的回答也很有帮助,因为它澄清了我在遵循 Dmitry 的指示后遇到的一些编码问题。如果我能够接受多个答案,我也会选择你的。
    猜你喜欢
    • 1970-01-01
    • 2013-10-08
    • 2015-08-15
    • 1970-01-01
    • 1970-01-01
    • 2015-10-01
    • 2017-02-15
    • 1970-01-01
    • 2011-07-19
    相关资源
    最近更新 更多