Send All Google Tasks in a Task List to Google GMail

From Ittichai Chammavanijakul's Wiki
Jump to: navigation, search

// Constant
TASKLIST = "Ittichai's list";  
// -----------------------------------------------------  

function getTasklistId_(tasklistName) {  
      var tasklistsList = Tasks.Tasklists.list();  
      var taskLists = tasklistsList.getItems();  
      for (tl in taskLists) {  
        var title = taskLists[tl].getTitle();  
        if (title == tasklistName) {  
          return taskLists[tl].getId();  
        }  
      }  
    }  

function main() {
  
    // Get the task ID defined in TASKLIST
    var tasklistid = getTasklistId_(TASKLIST)
    
    // Get all tasks in the task list
    var tasks = Tasks.Tasks.list(tasklistid).getItems();

    for(var i in tasks){
         var tasktitle = tasks[i].getTitle();
         var tasknotes = tasks[i].getNotes();
         MailApp.sendEmail('ittichai@gmail.com', tasktitle, tasknotes);

    }  
}