如何使用C#Task Scheduler Managed Wrapper发送电子邮件

时间:2015-08-14 20:17:22

标签: c# scheduled-tasks

使用以下code example我创建了一项任务:

using (TaskService ts = new TaskService())
      {
         // Create a new task definition and assign properties
         TaskDefinition td = ts.NewTask();
         td.RegistrationInfo.Description = "Does something";

         // Add a trigger that, starting tomorrow, will fire every other week on Monday
         // and Saturday and repeat every 10 minutes for the following 11 hours
         WeeklyTrigger wt = new WeeklyTrigger();
         wt.StartBoundary = DateTime.Today.AddDays(1);
         wt.DaysOfWeek = DaysOfTheWeek.Monday | DaysOfTheWeek.Saturday;
         wt.WeeksInterval = 2;
         wt.Repetition.Duration = TimeSpan.FromHours(11);
         wt.Repetition.Interval = TimeSpan.FromMinutes(10);
         td.Triggers.Add(wt)

         // 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);
      }
   }

但是如何以编程方式添加以下内容"发送电子邮件" Windows任务计划程序中显示的操作,用于我创建的任务: enter image description here

2 个答案:

答案 0 :(得分:0)

您要找的是EmailAction

答案 1 :(得分:0)

到达目的地的方式是blog。您必须创建类型

的新操作

_TASK_ACTION_TYPE.TASK_ACTION_SEND_EMAIL

并在任务注册期间绑定该操作