2014年6月7日土曜日

Google Apps Script(GAS)メール検索、送信

メール検索して送信・・・うーん
需要ないよねきっとw
意味ないもの
でもメール多くて埋もれる人はアリなのかもしれない

function mailsearch() {
//今日の日付取得
var today = Utilities.formatDate(new Date(), "JST", "yyyy/MM/dd");
//昨日の日付取得
var today2 = new Date();
var yesterday = new Date(today2.getTime()-1000*60*60*24);
var startDate = Utilities.formatDate(yesterday, "JST", "yyyy/M/dd");
//月末日取得
var end = new Date(today2.getFullYear(), today2.getMonth() + 1, 0)
var endDate = Utilities.formatDate(end, "JST", "yyyy/M/dd");

//宛先メールアドレス
var mail_to = "○○○";
 
//メール検索条件
var threads = GmailApp.search('○○○ after:'+startDate+' before:' + endDate +'',0,1);

//親スレッドにメッセージ指定
try{
var messages = threads[0].getMessages();
//本文取得
var tBody = messages[0].getBody();
//メール件名
var subject ="【○○○:" + today + "】";
//メール送信
MailApp.sendEmail(mail_to, subject, tBody);
}
catch(e)
{
}
}

0 件のコメント:

コメントを投稿