Prompt Details
Model
(gemini-3.5-flash)
Token size
311
Example input
[E mail: Gmail, Outlook]: Gmail
[Tool Automation: n8n, Zapier]: Google Apps Script
[DataSheet: Excel, Google Sheets]: Google Sheets
Example output
1. INTEGRATION METHOD
The integration leverages the native GmailApp and SpreadsheetApp services within the Google Apps Script runtime.
Trigger Mechanism: A time-driven trigger (e.g., every 5 or 15 minutes) executes the script.
Authentication: Uses OAuth 2.0 via the internal Google Apps Script execution context, requiring gmail.readonly and spreadsheets scopes.
Processing Flow: Script queries threads matching a specific query string (is:unread label:inbox), iterates through messages, passes content to the Gemini API, parses the JSON response, and appends rows to the target sheet.
2. PROCESSING LOGIC
/**
* Main function to bridge Gmail and Sheets via Gemini
*/
function processEmailsToSheets() {
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Data');
const threads = GmailApp.search('is:unread label:inbox', 0, 10);
threads.forEach(thread => {
const messages = thread.getMessages();
messages.forEach(message => {
if (message.isUnread()) {
const emailBody = message.getPlainBody();
const jsonResult = callGeminiForExtraction(emailBody);
// Append parsed data
sheet.appendRow([
message.getDate(),
jsonResult.sender,
jsonResult.subject,
jsonResult.summary,
jsonResult.category
]);
message.markRead();
}
});
});
}
function callGeminiForExtraction(text) {
const apiKey = 'YOUR_GEMINI_API_KEY';
const url = 'https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=' + apiKey;
const payload = {
"contents": [{ "parts": [{ "text": "Extract details from this email: " + text }] }],
"generationConfig": { "response_mime_type": "application/json" }
};
const response = UrlFetchApp.fetch(url, {
method: 'post',
contentType: 'application/json',
payload: JSON.stringify(payload)
});
return JSON.parse(JSON.parse(response.getContentText()).candidates[0].content.parts[0].text);
}
3. SYSTEM PROMPT
"You are an expert data extraction assistant. Analyze the provided email body and extract information into a valid JSON object. Do not include markdown formatting or conversational filler. Use the following schema:
{
"sender": "string",
"subject": "string",
"summary": "string",
"category": "string"
}
If a field is missing, return "N/A"."
4. DESTINATION SCHEMA
Timestamp: Date/Time (System generated)
Sender: String (Extracted)
Subject: String (Extracted)
Summary: String (Extracted)
Category: String (Extracted)
Or get it with Select10 Select prompts/mo — under $2 each
Learn moreBy purchasing this prompt, you agree to our terms of service
GEMINI-3.5-FLASH
Build your custom automation stack in seconds. The Universal Email AI Automation Architect generates professional technical blueprints for connecting any email source to your preferred automation engine and database. Whether using Gmail, Outlook, n8n, Make, or PostgreSQL, this prompt delivers precise integration methods, logic, and extraction schemas. Stop searching for tutorials—get a ready-to-deploy architecture tailored specifically to your tech stack.
...more
Updated 6 days ago
