gpt4 book ai didi

c# - 如果在 C# 中收到新的 Outlook 邮件,则启动方法

转载 作者:行者123 更新时间:2023-12-04 09:49:30 36 4
gpt4 key购买 nike

我有一个小问题。
恐怕我不知道从哪里或如何开始。

我的项目:
当我的 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...
}

您可能还会发现以下系列文章很有帮助:
  • Outlook NewMail event unleashed: the challenge (NewMail, NewMailEx, ItemAdd)
  • Outlook NewMail event: solution options
  • Outlook NewMail event and Extended MAPI: C# example
  • Outlook NewMail unleashed: writing a working solution (C# example)
  • 关于c# - 如果在 C# 中收到新的 Outlook 邮件,则启动方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62029370/

    36 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com