我有一个小问题。 恐怕我不知道从哪里开始或如何开始。
我的项目: 当我的 Outlook 邮箱中有一封主题为“START”的新电子邮件时,我想执行一个方法。
结构如下:
public void EmailNotification()
{
if (/* Check every 5 minutes as long as application is running for new mails in Outlook*/ || /*
subject contains the string "start" */){
AnyMethod();
}
}
public void AnyMethod()
{
// Do somethink
}
我希望我的问题得到清楚的解释。 我在 C# 方面仍然是一个相对初学者,很高兴能得到任何帮助。
如果我使用 IMAP 执行此操作,我担心我无法控制的交换服务器会阻止某些内容(因为安全规则,例如不受信任的应用程序),但我可以肯定我可以尝试一下。也许它有效。
最佳答案
您需要处理NewMailEx Outlook 对象模型中的 Application 类的事件。对于 Microsoft Outlook 处理的每个收到的项目,此事件都会触发一次。该项目可以是多种不同项目类型之一,例如 MailItem
、MeetingItem
或 SharingItem
。 EntryIDsCollection
字符串包含与该项目对应的条目 ID。
当新邮件到达收件箱且在客户端规则处理发生之前,将触发 NewMailEx
事件。您可以使用 EntryIDCollection
字符串中返回的条目 ID 来调用 NameSpace.GetItemFromID
方法并处理该项目。
void Application_NewMailEx(string EntryIDCollection)
{
Outlook.MailItem newMail = (Outlook.MailItem) Application.Session.GetItemFromID(EntryIDCollection, System.Reflection.Missing.Value);
// do whatever you want with the new email...
}
您可能还会发现以下系列文章很有帮助:
关于c# - 如果在 C# 中收到新的 Outlook 邮件,则启动方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62029370/