admin管理员组文章数量:1278795
Here's a neat javascript code I wrote to get all emails from my Gmail and put the list of sender name in a google spreadsheet.
function doGet()
{
var myspreadsheet = SpreadsheetApp.openById("0Atg1TJnn4dFdGbjNGSrMGJRdGc");
var mysheet = myspreadsheet.getSheets()[0];
var threads = GmailApp.getInboxThreads();
var messages = GmailApp.getMessagesForThreads(threads);
var froms = [];
for(var i = 0; i < threads.length; i++)
{
froms.push([messages[i][0].getFrom(),i]);
}
mysheet.getRange(1,1,threads.length,2).setValues(froms);
}
It works great but there're 2 issues
The GetInboxThreads method only gets the first 500 emails whatever you try. The question is does someone know how to get more than 500 ? How about get the last 500 rather than the first 500 emails ?
It's a bit slow, although I put loads of effort to make it efficient, can someone suggest how to retrieve the sender name from the emails and put that list of sender names on a spreadsheet in a quick way ?
Here's a neat javascript code I wrote to get all emails from my Gmail and put the list of sender name in a google spreadsheet.
function doGet()
{
var myspreadsheet = SpreadsheetApp.openById("0Atg1TJnn4dFdGbjNGSrMGJRdGc");
var mysheet = myspreadsheet.getSheets()[0];
var threads = GmailApp.getInboxThreads();
var messages = GmailApp.getMessagesForThreads(threads);
var froms = [];
for(var i = 0; i < threads.length; i++)
{
froms.push([messages[i][0].getFrom(),i]);
}
mysheet.getRange(1,1,threads.length,2).setValues(froms);
}
It works great but there're 2 issues
The GetInboxThreads method only gets the first 500 emails whatever you try. The question is does someone know how to get more than 500 ? How about get the last 500 rather than the first 500 emails ?
It's a bit slow, although I put loads of effort to make it efficient, can someone suggest how to retrieve the sender name from the emails and put that list of sender names on a spreadsheet in a quick way ?
- 1 method getInboxThreads(start, max) allows you to page through all the threads – DavidF Commented Dec 12, 2012 at 9:21
- Could you please clarify your answer ? how can I page through all the 4000 threads I have in my gmail ? – Mohamed Heiba Commented Dec 14, 2012 at 14:05
1 Answer
Reset to default 10Looks like about 10secs /100 messages this way. Can't think of anything faster in GAS.
function getMail(){
var inc = 100;
var start = 0;
do {
var now = new Date();
var thread = GmailApp.getInboxThreads(start, inc);
start += inc;
var messages = GmailApp.getMessagesForThreads(thread);
Logger.log("# threads"+thread.length+"# of messages" + messages.length+" time :"+(new Date()-now));
} while (thread.length == inc);
}
本文标签: javascriptHow to use Google App Scripts to retrieve Gmail emails in a customised wayStack Overflow
版权声明:本文标题:javascript - How to use Google App Scripts to retrieve Gmail emails in a customised way? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741254361a2366383.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论