如何创建 Outlook 加载项,以便在用户尝试回复域外发件人时向用户发出警报?
我是 C# 编码新手。我目前正在尝试创建一个 Outlook 加载项,以便在用户尝试回复非“@abc.com”的任何人时提示和提醒用户。例如,如果 '[email protected]' 是尝试回复 ' [电子邮件受保护]',系统会弹出一个警告 Ben 的窗口,警告他“您即将回复非来自 '@abc.com' 的人。”有“确定”和“取消”选项。
我在网上引用了下面的代码,但此加载项仅允许我编辑我尝试发送的电子邮件的字段值。我什至无法弄清楚如何处理和实现处理回复的代码。我尝试过在线研究并看到过像 .reply() 这样的方法,但我对如何应用它们感到困惑。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
namespace FirstOutlookAddIn
{
public partial class ThisAddIn
{
Outlook.Inspectors inspectors;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
inspectors = this.Application.Inspectors;
inspectors.NewInspector +=
new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector);
}
void Inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
{
Outlook.MailItem mailItem = Inspector.CurrentItem as Outlook.MailItem;
if (mailItem != null)
{
if (mailItem.EntryID == null)
{
mailItem.To = "Testing for Recipient.";
mailItem.Subject = "Currently testing add-in for Subject.";
mailItem.Body = "Currently testing add-in for Body.";
mailItem.CC = "Testing for CC.";
}
}
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
// Note: Outlook no longer raises this event. If you have code that
// must run when Outlook shuts down, see https://go.microsoft.com/fwlink/?LinkId=506785
}
#region VSTO generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
}
}
I am new to coding in c#. I am currently trying to create an Outlook add-in to prompt and alert users if they are to attempt to reply to anyone that is not from "@abc.com". For example if '[email protected]' is to trying to reply to '[email protected]', a window to alert Ben will be prompted warning him "You are about to reply to someone that is not from '@abc.com'." with the options of 'ok' and 'cancel'.
I referred online for the code below but this add-in only allows me to edit the field values of the email I am trying to send. I am unable to even figure out how to address and implement the code to deal with replying. I have tried researching online and have seen methods like .reply() but I am confused as to how to apply them.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
namespace FirstOutlookAddIn
{
public partial class ThisAddIn
{
Outlook.Inspectors inspectors;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
inspectors = this.Application.Inspectors;
inspectors.NewInspector +=
new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector);
}
void Inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
{
Outlook.MailItem mailItem = Inspector.CurrentItem as Outlook.MailItem;
if (mailItem != null)
{
if (mailItem.EntryID == null)
{
mailItem.To = "Testing for Recipient.";
mailItem.Subject = "Currently testing add-in for Subject.";
mailItem.Body = "Currently testing add-in for Body.";
mailItem.CC = "Testing for CC.";
}
}
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
// Note: Outlook no longer raises this event. If you have code that
// must run when Outlook shuts down, see https://go.microsoft.com/fwlink/?LinkId=506785
}
#region VSTO generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,您只是跟踪
Inspectors.newinspector
事件。但是在大多数情况下,答复将是内联的 - 您还需要explorer.inlineresponse
event(其中explorer
来自application.active> application.activeeviveexplorer
,它可以null null null在启动时,您还需要application.explorers.newexplorer
event)。其次,您需要在
mailItem.recipients
集合中循环循环,对于每个收件人
,请检查coce> contectient.address.address
property(您可以测试比赛)。Firstly, you are only tracking
Inspectors.NewInspector
event. But in most cases replies will be inline - you also needExplorer.InlineResponse
event (whereExplorer
comes fromApplication.ActiveExplorer
, which can be null on startup, so you'd also needApplication.Explorers.NewExplorer
event).Secondly, you will need to loop through all recipients in the
mailItem.Recipients
collection, and for eachRecipient
, check theRecipient.Address
property (which you can test for the match).监听
send
event
,因为无论inline
回复还是inspector
级别回复都会触发该事件。然后可以按如下方式实现此操作,
您可以在此处的 MS 博客中阅读此事件 Item_Send
Listen to
send
event
, as it will be triggered irrespective ofinline
replies orinspector
level replies.then implementation of this can be done as below,
you can read on this event in MS blog here Item_Send