0% found this document useful (0 votes)
6 views1 page

Extract Blog Submissions Script

The function 'extractAllEmailSubmissions' retrieves email submissions from the user's Gmail inbox and logs them into a Google Sheets document. It extracts the sender's name, USN, and section from the email body and appends this information to the sheet. After processing up to 200 email threads, it alerts the user with the total number of submissions logged.

Uploaded by

umeasm3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Extract Blog Submissions Script

The function 'extractAllEmailSubmissions' retrieves email submissions from the user's Gmail inbox and logs them into a Google Sheets document. It extracts the sender's name, USN, and section from the email body and appends this information to the sheet. After processing up to 200 email threads, it alerts the user with the total number of submissions logged.

Uploaded by

umeasm3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

function extractAllEmailSubmissions() {

const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();


sheet.clear();
sheet.appendRow(['Name', 'USN', 'Section', 'Email']);

const threads = GmailApp.getInboxThreads(0, 200);


let added = 0;

threads.forEach(thread => {
const msg = thread.getMessages().pop();
const body = msg.getPlainBody();
const from = msg.getFrom();

const nameMatch = body.match(/Name\s*[:\-]\s*(.+)/i);


const usnMatch = body.match(/USN\s*[:\-]\s*([A-Za-z0-9]+)/i);
const sectionMatch = body.match(/Section\s*[:\-]\s*([A-Za-z0-9]+)/i);

const name = nameMatch ? nameMatch[1].trim() : '';


const usn = usnMatch ? usnMatch[1].trim().toUpperCase() : '';
const section = sectionMatch ? sectionMatch[1].trim().toUpperCase() : '';

if (name || usn) {
sheet.appendRow([name, usn, section, from]);
added++;
}
});

SpreadsheetApp.flush();
SpreadsheetApp.getUi().alert('Done! ' + added + ' submissions logged.');
}

You might also like