Skip to content

Instantly share code, notes, and snippets.

@CodeLeom
Created March 1, 2024 20:03
Show Gist options
  • Save CodeLeom/695ff6c9ad79a5d19e12afabdb2164b1 to your computer and use it in GitHub Desktop.
Save CodeLeom/695ff6c9ad79a5d19e12afabdb2164b1 to your computer and use it in GitHub Desktop.
This is a demo of a simple appScript to get an email message and push the data into a google sheet file
function logEmailsToSheet() {
// Specify the subject line to search for in Gmail
var query = 'subject:"Feedback Submission"';
// Access the active spreadsheet and the first sheet
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
// Search Gmail with the given query
var threads = GmailApp.search(query);
for (var i = 0; i < threads.length; i++) {
var messages = threads[i].getMessages();
for (var j = 0; j < messages.length; j++) {
var message = messages[j];
// Extract date, sender, subject, and body from each email
var date = message.getDate();
var from = message.getFrom();
var subject = message.getSubject();
var body = message.getPlainBody();
// Append the data to the sheet
sheet.appendRow([date, from, subject, body]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment