
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to Extract Email Addresses from Gmail Messages
To extract email addresses from Gmail Messages, you have to use google sheets also Apps Script for automation. Open a New google sheets and navigate to Extensions. Then, set up script that scan your mailbox and lists sender emails address in the google sheets automatically.
Here's is step-by-step procedure to extract email addresses from Gmail messages is given follow these steps:-
Step 1: Open Google Sheets
Go to Google Sheets and create a new or Blank sheets.
Step 2: Open Apps Script
Click on Extension on clicking you will see many option among them select Apps Script.
Step 3: Add the Code
After clicking on Apps Script, the editor will appear. Delete all the existing code and paste the following code:
function extractEmailsToSpecificSheet() {
// Replace with your actual Spreadsheet ID
const spreadsheetId = 'Your_spreadhseet_ID';
// Replace with your actual Sheet name (e.g., "Sheet1")
const sheetName = 'Sheet1';
const ss = SpreadsheetApp.openById(spreadsheetId);
const sheet = ss.getSheetByName(sheetName);
sheet.clear(); // Clear old data
sheet.getRange("A1").setValue("Email Addresses");
const threads = GmailApp.getInboxThreads(0, 50); // You can increase the 50
const emailSet = new Set();
threads.forEach(thread => {
const messages = thread.getMessages();
messages.forEach(msg => {
const from = msg.getFrom();
const to = msg.getTo();
const cc = msg.getCc();
const combined = [from, to, cc].join(',');
const found = combined.match(/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/gi);
if (found) {
found.forEach(email => emailSet.add(email));
}
});
});
const emails = [...emailSet];
for (let i = 0; i < emails.length; i++) {
sheet.getRange(i + 2, 1).setValue(emails[i]); // Start from row 2
}
SpreadsheetApp.flush();
}
Access the code from https://bit.ly/4j7wqoD
Step 4: Find and Copy Google Spreadsheet ID
Spreadsheet ID is found in the URL of Google Sheet.
ID lies in between /d/ to /edit/. Paste the spreadsheet ID in code line 3.
Step 5: Save and Run the Script
Save and run the script -
Step 6: Authorize the Script
Authorize the script as follows -
Next, click on Review permissions -
Sign in with the same Gmail account linked to your Google Sheet.
Click on Go to unsafe
Click select all and then click continue.
Step 7: Verify the Execution log.
You will get to see the following message after the script ran successfully.
Step 8: Refresh the Google Spreadsheet
After you refresh the Google Spreadsheet, your email address will appear there.
Follow the steps given in this tutorial to extract the email addresses from Gmail messages.