Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save danielcranney/9fa14d9535f2ee7df20ce01d6f149a59 to your computer and use it in GitHub Desktop.
Save danielcranney/9fa14d9535f2ee7df20ce01d6f149a59 to your computer and use it in GitHub Desktop.
newsletter unsubscription tracker / 06 - read the contents of the emails.js
// Logs emails from threads labeled "unsubscribed" to a Google Sheet
function logUnsubscribes() {
var label = GmailApp.getUserLabelByName('unsubscribed');
var threads = label.getThreads();
var sheet = SpreadsheetApp.open(DriveApp.getFileById('1v77gBSUzF7evN5Rlnvsz27LgoHgowiLivPpAGeTMgBQ'));
threads.forEach(function(thread) {
var messages = thread.getMessages();
messages.forEach(function(message) {
var body = message.getBody(); // Get the body content of the email
var email = extractEmail(body); // Extract the email from the message body
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment