Google > GAS > Gmail

下位ページ

Content


構造「スレッド」と「メッセージ」

  • メッセージ:いわゆるメールの単位
  • スレッド:ある一つのメッセージに対する返信を束ねる

Mail

メールを送る

GmailApp.sendEmail(recipient, subject, body)

GmailApp.sendEmail(recipient, subject, body, options)
optionの使い方で添付ファイルを送ったりできる
sendEmail

GoogleDriveのファイルを添付する

optionsに
{attachmens : BlobSourse[]}
を指定

sendmailのサンプルを見てみると
var file = DriveApp.getFileById('1234567890abcdefghijklmnopqrstuvwxyz');
GmailApp.sendEmail('mike@example.com', 'Attachment example', 'Please see the attached file.', {attachments: [file.getAs(MimeType.PDF)], name: 'Automatic Emailer Script'});
とある。

BlobSourceを見てみると、そのなかに 「File : A file in Google Drive」 が存在。つまり、添付するファイルのオブジェクトを取得して、これを
{attachments: (File)}

で、Blobって一体?
バイナリ・ラージ・オブジェクト - Wikipedia
BLOB - Weblio辞書
いろんな形式のデータ、という程度の理解にとどめておく。なので、BlobSourceは、Blobのデータとして使えるものが書いてあるという理解。これらに関しては、
(BlobSource).getAs(contentType)
(BlobSource).getBlob()
で、そのままBlobにしたり、形式を変換してBlobにしたりできる。
getAs()
getBlob()

getAs(contentType)で、多くの場合に使えるのは 'application/pdf'
画像系なら 'image/bmp', 'image/gif', 'image/jpeg', or 'image/png'
が使える
上記のサンプルの中では、file.getAs(...) としているが、この関数でBlobが返っている。

メールを検索する

GmailApp.search(queryString)

メールの受信(送信)日時を取得する

objGmailMessage.getDate()
getDate
JavaScript/Date

メールを削除する(ゴミ箱行き)

objGmailMessage.MoveToTrash()
MoveToTrash
最終更新:2015年06月11日 00:02