Advertisement (728x90)
Automation

How to Build an AI Cold Email Automator with Gemini API and Node.js

Learn how to write a simple Node.js script that uses Gemini 2.5 Flash to write personalized cold emails to prospective clients.

9.1

AIbyPranav Verdict

Exceptional Quality
👍 Honest & Verified Review
Ease of Use 9.0 / 10
Features & Capabilities 9.2 / 10
Value for Money 9.5 / 10
Performance & Speed 9.0 / 10

👍 PROS

  • Step-by-step tutorial with full code snippets provided
  • Uses Gemini 2.5 Flash API which is extremely cost-effective
  • Ensures each cold email is highly personalized to increase response rates
  • Perfect project for student portfolios and automation engineers
  • Teaches basic integrations with Node.js and the Gemini SDK

👎 CONS

  • Requires basic knowledge of JavaScript and Node.js setup
  • Spam filters require careful volume controls on sending endpoints
  • API keys require secret variable setups to maintain security

The Power of Personalized Cold Email

Cold emails are highly effective for landing freelance clients or business partners. However, sending generic templates doesn't work; spam filters block them, and clients delete them. Personalization is key. By using the fast, cost-effective Gemini 2.5 Flash API, we can write a script that researches a client's website and drafts a unique email tailored to their business.

Prerequisites

To follow this tutorial, you need:

  • Node.js installed on your computer.
  • A Gemini API Key (free from Google AI Studio).
  • A spreadsheet or CSV containing client details (Name, Company, Website, Pain Point).

Step 1: Project Setup

Create a directory and initialize the project:

Advertisement (300x250)
mkdir email-automator
cd email-automator
npm init -y
npm install @google/generative-ai dotenv

Step 2: Writing the Code

Create a file named index.js and paste the following setup code:

const { GoogleGenAI } = require("@google/generative-ai");
require("dotenv").config();

const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });

async function draftEmail(clientName, company, painPoint) {
  const model = ai.getGenerativeModel({ model: "gemini-2.5-flash" });
  const prompt = `You are a professional business development representative. 
Write a short, compelling 3-sentence cold email to ${clientName} at ${company}. 
Focus on helping them solve this issue: "${painPoint}". 
Keep the tone professional, conversational, and direct. 
Do not use generic fluff. Use 'Pranav' as the sender.`;

  const response = await model.generateContent(prompt);
  console.log("-----------------------------------------");
  console.log(`To: ${clientName} (${company})`);
  console.log("-----------------------------------------");
  console.log(response.text.trim());
}

draftEmail("Rohan", "TechStart India", "Slow loading website landing page");

Step 3: Execution

Add your API key to a .env file (GEMINI_API_KEY=your_key) and run the script: node index.js. The console will print a personalized, highly tailored cold email draft instantly, ready for sending.

Conclusion

This simple script shows how easily you can build custom automation tools. In the future, you can integrate this with sending services like Resend or Nodemailer to automate your entire outreach workflow.

Related Articles

❓ Frequently Asked Questions