如何使用 C# Task Scheduler Managed Wrapper 发送电子邮件
How to send an email using C# Task Scheduler Managed Wrapper
使用以下 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 任务计划程序中显示的以下 "Send an email" 操作。:
您要查找的是EmailAction。
到达那里的方式是在这个 blog 中给出。您必须创建类型为
的新操作
_TASK_ACTION_TYPE.TASK_ACTION_SEND_EMAIL
并在任务注册期间绑定该操作[=12=]
使用以下 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 任务计划程序中显示的以下 "Send an email" 操作。:
您要查找的是EmailAction。
到达那里的方式是在这个 blog 中给出。您必须创建类型为
的新操作_TASK_ACTION_TYPE.TASK_ACTION_SEND_EMAIL
并在任务注册期间绑定该操作[=12=]