In this tutorial, I will show you how to select only those that correspond to a list of email addresses from the list of emails received on a Gmail account.
Obviously, you can modify this script to perform other operations: delete them, assign them a label, …
Create a spreadsheet in Google Drive and from the main menu select: Extensions – Apps Script to create a new Google apps script.
In this script, you will have to enter this example source code and change the email addresses in the list:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | function getEmails() { // Replace emailList with a list of email addresses var emailList = [ "notifications@sketchfab.com>", "newsletter@info.evomag.ro", "oferte@e2.emag.ro" ]; // Get the current active sheet var sheet = SpreadsheetApp.getActiveSheet(); // Loop through the email list for (var i = 0; i < emailList.length; i++) { // Get the email address var email = emailList[i]; // Use the Gmail API to get the email messages for this email address var messages = Gmail.Users.Messages.list("me", {q: "from:" + email}); // Loop through the messages for (var j = 0; j < messages.messages.length; j++) { // Get the message var message = messages.messages[j]; // Get the message id var messageId = message.id; // Use the Gmail API to get the message details var messageDetails = Gmail.Users.Messages.get("me", messageId); // Get the message subject and body var subject = messageDetails.payload.headers.find(function(header) { return header.name.toLowerCase() === "subject"; }).value; var body = messageDetails.payload.body.data; // Add the subject and body to the spreadsheet sheet.appendRow([subject, body]); } } } |
In the editor on the left, you have a button: Services and you must choose the Gmail service.
Dupa ce ati salvat scriptul din meniul principal, veti putea rula functia: function getEmails.
You will be asked to authorize this operation and in the spreadsheet, you should have the result with the sorted emails.
Here is the result of running the script: