LoginSignup
3
5

More than 5 years have passed since last update.

【GAS】Googleカレンダーの今日の日程を定期的にメールする

Last updated at Posted at 2018-06-20

概要

Googleカレンダーにある今日の日程をメールしてくれます.

こんな感じです.

今日の予定
08時00分 - 08時30分 : 散歩
15時00分 - 18時00分 : プログラミング
18時00分 - 18時30分 : 夕飯
20時00分 - 21時00分 : お風呂
21時00分 - 03時00分 : バイト

内容

function myFunction() {
  const calendar = CalendarApp.getCalendarById('カレンダーID');
  const events = calendar.getEventsForDay(new Date());

  //時間の整形
  function makeTime(Date) {
    function addZero(num) {
      return (num <= 9 ? '0' : '') + num;
    }
    return addZero(Date.getHours()) + '' + addZero(Date.getMinutes()) + '';
  }

  var body = events.reduce(function(tmp, event) {
    return tmp + makeTime(event.getStartTime()) + ' - ' + makeTime(event.getEndTime()) + ' : ' + event.getTitle() + '\n';
  }, '');

  //メール送信
  MailApp.sendEmail({
    to: '送りたい相手のメールアドレス',
    subject: '今日の予定',
    body: body
  });

}

後はこれにGASのトリガーをセットすると定期的に今日の日程を送ってくれます.
また,特定の時間帯の予定だけメールしたり,特定の言葉が入っている物のみメールしたりもできると思います.
これとは別ですが,カレンダーの予定から自動でメールしてくれるような応用もできると思います.

参考資料

Calendar Service  |  Apps Script  |  Google Developers

3
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
5