Reputation: 159
I have a little problem. I'm afraid I don't know where or how to begin.
My project: When I have a new e-mail in my Outlook mailbox with the subject "START" I want to execute a method.
In the following structure:
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
}
I hope my problem is clearly explained. I am still a relative beginner in C# and am happy for any help.
I am afraid that the exchange server, which I cannot control, is blocking something if I do it with IMAP (because of sercurity rules e.g. untrusted application) but for sure I can try it. Maybe it works.
Upvotes: 2
Views: 931
Reputation: 49455
You need to handle the NewMailEx event of the Application class from the Outlook object model. This event fires once for every received item that is processed by Microsoft Outlook. The item can be one of several different item types, for example, MailItem
, MeetingItem
, or SharingItem
. The EntryIDsCollection
string contains the Entry ID that corresponds to that item.
The NewMailEx
event fires when a new message arrives in the Inbox and before client rule processing occurs. You can use the Entry ID returned in the EntryIDCollection
string to call the NameSpace.GetItemFromID
method and process the item.
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...
}
You may also find the following series of articles helpful:
Upvotes: 2