1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[GAS] Gmailの下書きを定期的に自動生成する

Last updated at Posted at 2018-04-23

ポイント

**レンダリング(太字や箇条書き)**を行う場合、オプション引数のhtmlBody要素を必ず指定するだけでなく、プレーンテキストにも何らかの文字を指定すること。

スクリプト


function createDailyGreetingDraft () {
  // 本文(プレーンテキスト)
  const mailBody = 'HTMLが表示できません'
  // 本文(HTML)
  const mailHtmlBody = 'おはよー<br><br>いえ〜い'

  // 宛先 To
  const mailTo = "aaa@example.com, bbb@example.com, ccc@example.com"
  // 宛先 Cc
  const mailCc = "ddd@example.com, eee@example.com"

  // オプションでCcを指定
  var mailArgs = { 
    cc: mailCc,
    htmlBody: mailHtmlBody //HTMLレンダリングを適用する場合は、これの指定が必須
  }
  
  // 下書きを生成
  GmailApp.createDraft(
    mailTo,         //To
    createTitle(),  //件名
    mailBody,       //本文
    mailArgs        //オプション
  )
}

// 件名の生成
function createTitle() {
  // 件名の日時フォーマット
  const date_format = 'yyMMdd'
  
  var now = new Date()
  var date = Utilities.formatDate( now, 'Asia/Tokyo', date_format)
  var title = date + "の挨拶 "
  
  return title
}

あとは、時計ボタンを押して、定期的な実行を設定すれば完了。

1
3
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
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?