invitation india
UnexpectedWeb
Connect

Popular Technology Blog where you'll find some interesting things around the web, that you never knew existed.

link Link copied

How to Import mail Subject and message from gmail into Spreadsheet

Share on: link Link copied
Learn how Save Gmail Messages Subject and message to a Google Spreadsheet using Google Apps Script.

You are trying to transfer gmail message subject and body content into google sheets or microsoft Excel ? Well I am build a simple script using Google Apps Script that would export subject lines and message body of up to the first 500 emails in your Inbox.

Max first 500 messages are to be saved at once using this Script. To get started, open Google Sheet and go to Tools > Script Editor.. , paste the code in the script editor of a Google Spreadsheet and run any of these functions according to your requirement from the Run menu.

Save Email Subjects :
function importSubject() {
  // Log the subject lines of up to the first 50(change up to 500) emails in your Inbox
 var threads = GmailApp.getInboxThreads(0, 50);
 var subno = 'A'; // Select column
  var j=1; //counter for row no
  
  for (var i = 0; i < threads.length; i++) {
   
   subno = 'A' + j;// generate cell address
   SpreadsheetApp.getActiveSheet().getRange(subno).setValue(threads[i].getFirstMessageSubject());//get the subject of threads[i]
    j++;
 }
}
Save Email message Content/Body in plane Text :


function importMessage() {
  // Log the subject lines of up to the first 50 emails in your Inbox
 var threads = GmailApp.getInboxThreads(0, 50);
 var subno = 'B';
  var j=1;
  for (var i = 0; i < threads.length; i++) {
      subno = 'B' + j;
     var message = threads[i].getMessages()[0];  // get first message of thread[i]
   SpreadsheetApp.getActiveSheet().getRange(subno).setValue(message.getPlainBody());// get message body in plain text (not in html code) of threads[i]
    j++;
 }
}
Save Email Subject and message Content/Body in plane Text :
function importSubjectAndMessage() {
  // Log the subject lines of up to the first 50 emails in your Inbox
 var threads = GmailApp.getInboxThreads(0, 50);
 var subno = 'A'; // Select column
  var msgno = 'B';
  var j=1; //counter for row no
  
  for (var i = 0; i < threads.length; i++) {
   
   subno = 'A' + j;// generate cell address
    msgno = 'B' + j;
   SpreadsheetApp.getActiveSheet().getRange(subno).setValue(threads[i].getFirstMessageSubject());//get the subject of threads[i]
     var message = threads[i].getMessages()[0];  // get first message of thread[i]
   SpreadsheetApp.getActiveSheet().getRange(msgno).setValue(message.getPlainBody());// get message body in plain text (not in html code) of threads[i]
    j++;
 }
}


No comments:

Powered by Blogger.