从外部程序回复(打开的)outlook 邮件

Reply to an (open) outlook mail from an external program

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

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

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

使用Application.ActiveExplorer.CurrentItem访问当前打开的邮件,然后调用MailItem.Reply获取回复MailItem对象,修改其邮件正文(MailItem.Body),调用MailItem.Display向用户展示。

发送电子邮件的 Reply method of Outlook items creates a reply, pre-addressed to the original sender, from the original message. You just need to get the currently opened email, call the Reply method on it and use the Send 方法。

要在资源管理器中获取当前显示的电子邮件 window 您需要使用资源管理器 class 的选择 属性(请参阅应用程序的 ActiveExplorer 功能 class).对于 Inspector windows,您可以使用 Inspector class 的 CurrentItem 属性(请参阅应用程序 class 的 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 文章很有帮助。