自动化电子邮件警报通知

本文关键字:通知 电子邮件 自动化 | 更新日期: 2023-09-27 17:59:13

我能够编码出间隔或每天自动发送电子邮件警报,但与3个月相比,我似乎无法成功编码。

我的场景是,这个自动化的电子邮件系统将不得不检索和检查我的数据库表这个合同的结束日期,如果今天的日期刚好是结束日期前3个月,我需要这个系统自动生成一封给这个合同客户的电子邮件,提醒他们联系我们。

有什么建议我该怎么编码吗?非常感谢您的帮助!

已编辑

@v2v2感谢您建议使用窗口服务。目前我面临的另一个问题是,我不知道如何改变间隔,以检查提前3个月,就像我在上面的场景中描述的那样。提前感谢,非常感谢您的帮助!

   <?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key ="Mode" value ="DAILY"/>
    <!-- <add key ="Mode" value ="Interval"/>-->
    <add key ="IntervalMinutes" value ="1"/>
    <add key ="ScheduledTime" value ="19:01:00"/>
  </appSettings>
</configuration>

自动化电子邮件警报通知

为什么不编写一个代码并使用Window任务调度器/ow窗口服务/或在代码中对其进行编程呢。

仅用于例如:

使用系统;使用Microsoft.Win32.TaskScheduler;

class Program
{
   static void Main(string[] args)
   {
      // Get the service on the local machine
      using (TaskService ts = new TaskService())
      {
         // Create a new task definition and assign properties
         TaskDefinition td = ts.NewTask();
         td.RegistrationInfo.Description = "Does something";
         // Create a trigger that will fire the task at this time every other day
         td.Triggers.Add(new DailyTrigger { DaysInterval = 2 });
         // Create an action that will launch Notepad whenever the trigger fires
         td.Actions.Add(new ExecAction("notepad.exe", "c:''test.log", null));
         // Register the task in the root folder
         ts.RootFolder.RegisterTaskDefinition(@"Test", td);
         // Remove the task we just created
         ts.RootFolder.DeleteTask("Test");
      }
   }
}

或者使用Window服务。使用谷歌并尝试,你可以找到足够的方法。请自己尝试,然后粘贴代码,如果你需要一些帮助。