From 1c71c22df79541dab007d43bd173463475f1ce73 Mon Sep 17 00:00:00 2001 From: woni <320753691@qq.com> Date: Mon, 11 Sep 2023 20:55:36 +0800 Subject: [PATCH] Add project files. --- OutlookEmailListener.csproj | 25 +++++++++++++++++++++++++ OutlookEmailListener.sln | 25 +++++++++++++++++++++++++ Program.cs | 25 +++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 OutlookEmailListener.csproj create mode 100644 OutlookEmailListener.sln create mode 100644 Program.cs diff --git a/OutlookEmailListener.csproj b/OutlookEmailListener.csproj new file mode 100644 index 0000000..d7b8f36 --- /dev/null +++ b/OutlookEmailListener.csproj @@ -0,0 +1,25 @@ + + + + Exe + net8.0 + enable + enable + true + true + true + + + + + tlbimp + 6 + 9 + 00062fff-0000-0000-c000-000000000046 + 0 + false + true + + + + diff --git a/OutlookEmailListener.sln b/OutlookEmailListener.sln new file mode 100644 index 0000000..f3377e0 --- /dev/null +++ b/OutlookEmailListener.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.7.34024.191 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OutlookEmailListener", "OutlookEmailListener.csproj", "{60CA6935-828C-4DEC-B53E-4EB8901A6E6E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {60CA6935-828C-4DEC-B53E-4EB8901A6E6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {60CA6935-828C-4DEC-B53E-4EB8901A6E6E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {60CA6935-828C-4DEC-B53E-4EB8901A6E6E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {60CA6935-828C-4DEC-B53E-4EB8901A6E6E}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {0039364C-28A1-465F-803B-F4D57B077D44} + EndGlobalSection +EndGlobal diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..56a0b6c --- /dev/null +++ b/Program.cs @@ -0,0 +1,25 @@ +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); + } + } +} \ No newline at end of file