25 lines
742 B
C#
25 lines
742 B
C#
namespace OutlookEmailListener;
|
|
|
|
using Outlook = Microsoft.Office.Interop.Outlook;
|
|
|
|
internal class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
Outlook.Application outlookApp = new Outlook.Application();
|
|
Outlook.MAPIFolder inbox = outlookApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
|
|
Outlook.Items items = inbox.Items;
|
|
items.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(OnNewMail);
|
|
|
|
Console.WriteLine("Press any key to exit...");
|
|
Console.ReadKey();
|
|
}
|
|
|
|
private static void OnNewMail(object item)
|
|
{
|
|
if (item is Outlook.MailItem mail)
|
|
{
|
|
Console.WriteLine("New mail received: {0}", mail.Subject);
|
|
}
|
|
}
|
|
} |