1
2

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 1 year has passed since last update.

Google Apps Script(GAS)でメールを送信メモ

Posted at

メール送信

メール送信はびっくりするくらい簡単でした。

今までGASで試すを全然やってなかったけど早く知っておくべきだった...

function sendMail(to = 'hogehoge@hoge.com') {
  const subject = '~~件名~~'; // メールの件名
  const options = {
    name: 'のび'
  };
  
  let body = `メール本文`;
  GmailApp.sendEmail(to, subject, body, options);
}

optionsにfromを指定できるけど自身のアドレスかエイリアスじゃないとエラーになります。

  const options = {
    name: 'のび',
    from: 'hogehoge@yahoo.co.jp' // これだとエラーになる。
  };

偽装できちゃいますからね。

スプレッドシートから情報取得して送信

mailbodyシートのA1セルに本文を書いておく想定です。

function sendMail(to = 'hogehoge@hoge.com') {
  const subject = '~~件名~~'; // メールの件名
  const options = {
    name: 'のび'
  };
  
  const SSID = `スプレッドシートID`;
  const sheet = SpreadsheetApp.openById(SSID);
  const range = sheet.getRange(`mailbody!A1`);
  const body = range.getValue();

  GmailApp.sendEmail(to, subject, body, options);
}
1
2
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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?