Extracting email addresses from text is a common yet tedious task for developers, marketers, and data analysts. However, new tools, such as rapid application development environments and AI give us everything we need to fully automate this task. Whether emails are hidden in website code, documents, or freeform text, efficient tools can identify and compile them into organized lists at the click of a button.
By automating this process, you save time, avoid manual errors, and ensure no valuable contact information is overlooked. This guide covers a simple method of extracting emails from text, using Five and an AI tool or LLM, such as OpenAI’s ChatGPT.
Check out our free sample application for extracting emails from text. The application accepts a text input and returns a structured list of all email addresses.
Here’s how the application works:
1. First, open the application, and click AI Extractor in the left-hand menu.
2. Paste the text containing email addresses into the Input box.
Note: this is a publicly accessible template application. We do not recommend pasting real email addresses. Here’s a sample text to try the email extractor.
/* hello@world.xyz, Jane Doe. homer@thesimpsons.com, Homer (male). bart@thesimpsons.com, Bart (son of Homer Simpson). Maggie Simpsons' email is maggie@thesimpsons.com.n*/
3. Click Extract. Once the extraction is completed, a success message appears: AI Extraction Complete. Click OK to confirm.
4. Go to Emails in the menu on the left side of the application. This is a list of all the emails extracted.
5. To filter through the emails, go to Email Filter on the left-hand side. Select today’s Date to narrow down your selection of email addresses. You can further filter for specific emails by hovering over the header columns of the table at the bottom. Each column is fully filterable.
From here, you can also export your list of email addresses as a CSV file. To do so, click the Export to CSV button near the top right corner.
Now that you have a list of the email addresses that were contained in your text, you can go ahead and import the addresses into your CRM or marketing automation system.
For permanent access to a login-protected email extractor, sign up for one of our subscription plans. Add additional features, such as sending out emails, passing on emails to your CRM, or enriching emails with additional information.
The “Extract Email” is a free sample application developed in Five, a rapid application development environment.
Five provides us with everything we need to develop this application:
Beyond that, Five also lets us
Follow the steps below to build your own AI-powered email extraction tool.
Let’s say you’re not just looking for emails but also for contact details, such as first name, last name, organization, and email. You have been given an event participant list and your job is to extract these four pieces of information from it. Unfortunately, the list is messy and unstructured.
Here’s how to tackle this challenge:
1. Sign up for a free trial of Five’s development environment.
2. Model your database.
If you’re not sure how to model a database in Five, follow our series of blog posts on database modeling. Remember, the database is what structures your data. So if you plan to extract three, five, or seven pieces of information from an unstructured input, you should have three, five, or seven database fields.
3. Create your user interface.
All we need are a few forms. Use Five’s Form Wizard to add them to your user interface.
4. Add the JavaScript functions to prompt your LLM.
We need two functions: one that runs on the client and one that runs on the server.
The client-side function holds the fields sent to AI as variables. Here’s what our client-side function for the sample app above looks like:
function OpenAIClient(five, context, result) {
const input = five.field.Input;
const variables = {};
variables["Input"] = input;
five.executeFunction("OpenAIServer", variables, null, null, null, function (result) {
five.showMessage("Extraction Complete");
})
return five.success(result);
}
Our server-side function does the heavy lifting and contains our AI prompt. Don’t forget to insert your own API code in line 2.
function OpenAIServer(five, context, result) {
const apiKey = 'API Key'
const client = five.httpClient();
client.addHeader("Authorization", `Bearer ${apiKey}`);
client.addHeader('Content-Type', 'application/json');
client.setContentType("application/json");
const messages = [
{
role: "developer",
content: `You are a text scraper. Give me a JSON response which contains an array called Email containing each of the emails within the input.`,
},
{
role: "user",
content: `${context.Input}`,
},
];
const parseData = {
model: "gpt-4o",
messages: messages
}
client.setContent(JSON.stringify(parseData));
let results = client.post("https://api.openai.com/v1/chat/completions")
const content = results.response.choices[0].message.content;
const jsonString = content.replace(/```json\n|\n```/g, '');
const parsedResponse = JSON.parse(jsonString);
const { Email } = parsedResponse
const emails = Email.toString().split(",");
const sql = "INSERT INTO Email (EmailKey, Email, DateOfExtraction) VALUES (?,?,?)";
for (let i = 0; i < emails.length; i++) {
five.executeQuery(sql, 0, five.uuid(), emails[i], five.now());
}
return five.success(result);
}
Last, hit Extract and let AI populate your database.
Note: as with any AI tool be aware of hallucination and make sure the extracted emails are valid before running an email campaign.
5. Test the application.
Once you’re done developing, remember to test the application so that it works as intended.
Accelerate Your Development: If you get stuck at any of these steps, post on our user community to contact our team of developers.
To extract emails from a text, follow these steps:
Tools like Five simplify this process for rapid application development. With Five, you can build a simple AI-driven application that extracts emails from text in minutes. Just follow the steps above.
Extracting email addresses from unstructured text is essential for managing contact lists efficiently. With the right tools, you can transform disorganized text into structured, actionable data. Automating the extraction process ensures accuracy and saves time, whether emails are hidden in web pages, documents, or raw text files.
Extracting and organizing emails is a critical step for effective communication and data-driven decision-making in any industry.