2015-08-14 67 views
3

使用以下code example電子郵件我創建了一個任務:如何發送使用C#任務計劃託管包裝

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

回答

0

你在找什麼是EmailAction

+0

使用你的建議,我成功地創建了電子郵件操作過程中結合的行動。但是,如果任務失敗,我想發送一封電子郵件。所以我[在這裏創建了一個新帖子](http://stackoverflow.com/questions/32018859/using-c-sharp-task-scheduler-managed-wrapper-how-to-trap-an-error-if-task-失敗)。 – nam

0

到達那裏的方法是blog。你必須創建類型

_TASK_ACTION_TYPE.TASK_ACTION_SEND_EMAIL

的新動作和任務註冊

+0

我正在使用[Task Scheduler Managed Wrapper](http://taskscheduler.codeplex.com/) – nam