Skip to content

nikhilmantri0902/Cold_Emailer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

47 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Cold Emailer - AI-Powered Job Application Outreach System

A comprehensive Golang-based cold email outreach system that automates personalized job application emails to recruiters and CTOs. The system integrates Apollo API for company and contact discovery, OpenAI for intelligent email generation, and Gmail API for sending emails with resume attachments. Includes a web-based dashboard for monitoring and management.

๐Ÿš€ Features

โœ… Core Functionality

  • Profile Management: Upload and store your profile information and resume
  • Apollo Integration: Automatically discover companies and contacts using Apollo's API
  • Smart Company & Contact Enrichment: Enrich database with companies and contacts filtered by country, employee range, and industry
  • AI-Powered Email Generation: Generate personalized emails using OpenAI with contact and company context
  • Gmail Integration: Send emails with resume attachments via Gmail API OAuth
  • Comprehensive Logging: Track email generation, sending, and error states with detailed logs
  • Rate Limiting: Built-in rate limiting for all external API calls
  • Database Management: PostgreSQL with proper schema, migrations, and indexing

๐Ÿ–ฅ Frontend Dashboard

  • Web-Based Interface: Clean, responsive dashboard for monitoring and management
  • Email Logs Viewer: Paginated display of all email activities with filtering options
  • Company Browser: Interactive company directory with search and filtering
  • Contact Management: View detailed contact information organized by company
  • System Configuration: Display of current targeting parameters and filters
  • Real-time Data: Live updates from the backend API
  • Tab-Based Navigation: Organized interface with separate sections for different functionalities

๐Ÿ”„ Complete Pipeline Flow

  1. Profile Setup: Upload your profile information and resume
  2. Gmail Authentication: Complete OAuth flow for email sending
  3. Database Enrichment: Discover and store companies/contacts from Apollo API
  4. Company Details Backfill: Enhance company information with detailed data
  5. Email Generation: Create personalized emails using AI for selected contacts
  6. Email Sending: Send emails with resume attachments and track status
  7. Follow-up Management: Send follow-up emails to previously contacted leads

๐Ÿ›  Technology Stack

  • Backend: Go 1.23 with Gin web framework
  • Frontend: Static HTML/CSS/JavaScript with Nginx
  • Database: PostgreSQL 15 with migrations
  • External APIs:
    • Apollo API for company/contact discovery
    • OpenAI API (GPT-3.5-turbo) for email generation
    • Gmail API for email sending
  • File Storage: Local file system with organized storage structure
  • Authentication: Gmail OAuth 2.0
  • Web Server: Nginx (reverse proxy + static file serving)
  • Deployment: Docker & Docker Compose
  • Logging: Structured logging with zerolog

๐Ÿ“‹ Prerequisites

  • Go 1.23+
  • PostgreSQL 15+
  • Docker & Docker Compose (recommended)
  • API Keys for:
    • OpenAI API
    • Apollo API
    • Gmail API (OAuth credentials)

๐Ÿš€ Quick Start

1. Clone the Repository

git clone https://github.com/nikhilmantri0902/Cold_Emailer
cd Cold_Emailer

2. Environment Configuration

Create a .env file in the root directory:

# Server Configuration
PORT=8000

# OpenAI Configuration
OPENAI_API_KEY=your-openai-api-key
OPENAI_MODEL=gpt-3.5-turbo
OPENAI_TEMPERATURE=0.7
OPENAI_MAX_COMPLETION_TOKENS=512

# Gmail OAuth Configuration
GMAIL_CLIENT_ID=your-gmail-client-id
GMAIL_CLIENT_SECRET=your-gmail-client-secret
GMAIL_REDIRECT_URI=http://localhost:8000/gmail-oauth2callback

# Apollo API Configuration
APOLLO_API_KEY=your-apollo-api-key

# Database Configuration (for local development)
DB_HOST=localhost
DB_PORT=5432
DB_USER=coldemailer
DB_PASSWORD=coldemailer
DB_NAME=coldemailer

3. Using Docker Compose (Recommended)

# Start all services (backend, frontend, database)
docker-compose up --build

# Run in background
docker-compose up -d --build

# Services started:
# - Backend API: http://localhost:8000
# - Frontend Dashboard: http://localhost:3000  
# - PostgreSQL Database: localhost:5432

4. Manual Setup (Alternative)

# Install dependencies
go mod tidy

# Start PostgreSQL (ensure it's running)
# Update constants/constants.go with your DB connection string

# Run migrations and start server
go run cmd/server/main.go

5. Verify Installation

# Check backend API
curl http://localhost:8000/health
# Response: {"status":"ok"}

# Access frontend dashboard
open http://localhost:3000

๐ŸŒ Access Points

Frontend Dashboard

  • URL: http://localhost:3000
  • Features:
    • Email Logs tab with pagination and filtering
    • Companies & Contacts tab with search functionality
    • System configuration display
    • Real-time data from backend API

Backend API

๐Ÿ“ก API Endpoints

Profile Management

Upload Profile & Resume

POST /api/profile
Content-Type: multipart/form-data

Form Data:
- name: string (required)
- email: string (required) 
- phone: string (optional)
- linkedin_url: string (optional)
- experience: string (optional)
- skills: string (optional)
- summary: string (optional)
- resume: file (optional - PDF/DOC)

Database Enrichment

Enrich Database with Companies & Contacts

POST /api/enrich-database
Content-Type: application/json

{
  "count_new_companies": 50,
  "max_contacts_per_company": 5
}
  • Fetches companies from Apollo API filtered by:
    • Target countries: Germany, Netherlands, Canada, Sweden, Finland, Norway, Ireland, UK, Luxembourg, UAE, Singapore, Australia
    • Employee ranges: 1-10, 11-50, 51-200, 201-500
    • Industries: Technology, Software, IT, AI
  • Discovers contacts with suitable roles: CTO, Talent Acquisition, Technical Recruiter, Product Manager

Backfill Company Details

POST /api/backfill-company-details
  • Enhances existing companies with detailed information from Apollo

Email Operations

Generate Single Email

POST /api/generate-email
Content-Type: application/json

{
  "contact_id": "uuid-of-contact"
}

Send Single Email

POST /api/send-single-email
Content-Type: application/json

{
  "contact_id": "uuid-of-contact"
}

Send Initial Outreach Emails (Batch)

POST /api/send-few-initial-emails
  • Automatically selects up to 10 contacts without prior email history
  • Generates personalized emails using AI
  • Sends emails with resume attachments
  • Logs all activities with status tracking

Send Follow-up Emails (Batch)

POST /api/send-few-follow-up-emails
  • Sends follow-up emails to previously contacted leads
  • Excludes recent contacts (within last 7 days)

Gmail Authentication

Initiate Gmail OAuth

GET /gmail-auth-initiate
  • Redirects to Gmail OAuth consent screen

OAuth Callback (Automatic)

GET /gmail-oauth2callback?code=...&state=...
  • Handles OAuth callback and stores tokens

Frontend API Endpoints

Get Email Logs (with Pagination)

GET /api/email-logs?page=1&limit=10&stage=INITIAL
  • Returns paginated email logs with company and contact details
  • Query Parameters:
    • page: Page number (default: 1)
    • limit: Records per page (default: 10, max: 100)
    • stage: Filter by email stage (INITIAL, FOLLOWUP) - optional

Get All Companies

GET /api/companies
  • Returns all companies in the database with full details

Get Company Contacts

GET /api/companies/{company_id}/contacts
  • Returns all contacts for a specific company

Get System Configuration

GET /api/config
  • Returns current targeting configuration (countries, roles, company sizes, industries)

Monitoring & Status

Health Check

GET /health

System Status

GET /api/status
  • Returns database connection status and system health

Email Logs (Legacy)

GET /api/logs
  • Returns recent email generation and sending logs

๐Ÿ—„ Database Schema

Tables Overview

profile_info

Stores user profile and resume information

- id (UUID, Primary Key)
- created_at (Timestamp)
- status (Text)
- name (Text, Required)
- email (Text, Required)
- phone (Text)
- linkedin_url (Text)
- experience (Text)
- skills (Text)
- summary (Text)
- resume_path (Text)
- metadata (JSONB)

companies

Companies discovered from Apollo API

- id (UUID, Primary Key)
- created_at (Timestamp)
- status (Text)
- apollo_id (Text, Indexed)
- name (Text)
- website (Text)
- industry (Text, Default: 'TECH')
- sub_industry (Text)
- tech_details (Text)
- company_details (Text)
- metadata (JSONB)

contacts

Contacts associated with companies

- id (UUID, Primary Key)
- created_at (Timestamp)
- company_id (UUID, Foreign Key)
- apollo_id (Text, Indexed)
- status (Text)
- name (Text)
- email_id (Text)
- phone_number (Text)
- linkedin_url (Text)
- role (Text)
- metadata (JSONB)

email_logs

Email generation and sending activity logs

- id (UUID, Primary Key)
- contact_id (UUID, Foreign Key)
- company_id (UUID, Foreign Key)
- status (Text) -- GENERATED, SENT, ERROR
- email_stage (Text) -- INITIAL, FOLLOWUP
- email_subject (Text)
- email_body (Text)
- attachment_details (JSONB)
- error_message (Text)
- metadata (JSONB)
- created_at (Timestamp)

gmail_tokens

Gmail OAuth tokens for email sending

- id (UUID, Primary Key)
- created_at (Timestamp)
- access_token (Text)
- refresh_token (Text)
- token_type (Text)
- expiry (Timestamp)

๐Ÿ”ง Configuration

Target Settings

  • Countries: Germany, Netherlands, Canada, Sweden, Finland, Norway, Ireland, UK, Luxembourg, UAE, Singapore, Australia
  • Company Sizes: 1-10, 11-50, 51-200, 201-500 employees
  • Industries: Technology, Software, IT, Artificial Intelligence
  • Target Roles: CTO, Talent Acquisition, Technical Recruiter, Product Manager

AI Email Generation

  • Model: GPT-3.5-turbo (configurable)
  • Temperature: 0.7 (configurable)
  • Max Tokens: 512 (configurable)
  • Prompt: Professional cold outreach with IIT Kharagpur background, company research, and skill highlighting

๐Ÿ“ Project Structure

cold_emailer/
โ”œโ”€โ”€ api/                    # HTTP handlers and API logic
โ”‚   โ”œโ”€โ”€ handlers.go        # Main API endpoint handlers
โ”‚   โ”œโ”€โ”€ helpers.go         # Business logic helpers
โ”‚   โ””โ”€โ”€ models.go          # Request/response models
โ”œโ”€โ”€ apollo/                # Apollo API integration
โ”‚   โ”œโ”€โ”€ client.go          # Apollo API client
โ”‚   โ”œโ”€โ”€ apollocompanydetails.go
โ”‚   โ”œโ”€โ”€ apollocompanysearchstructs.go
โ”‚   โ”œโ”€โ”€ apollocontactsearchrequest.go
โ”‚   โ””โ”€โ”€ apolloenrichcontact.go
โ”œโ”€โ”€ cmd/server/            # Application entry point
โ”‚   โ””โ”€โ”€ main.go           # Main server setup
โ”œโ”€โ”€ constants/             # Application constants
โ”‚   โ”œโ”€โ”€ constants.go      # Environment variables and settings
โ”‚   โ”œโ”€โ”€ errors.go         # Error definitions
โ”‚   โ”œโ”€โ”€ helpers.go        # Utility functions
โ”‚   โ””โ”€โ”€ prompts.go        # AI prompts
โ”œโ”€โ”€ db/                    # Database connection and management
โ”‚   โ””โ”€โ”€ db.go             # Database initialization and migrations
โ”œโ”€โ”€ dbmodels/              # Database models (one per table)
โ”‚   โ”œโ”€โ”€ companies/        # Company model operations
โ”‚   โ”œโ”€โ”€ contacts/         # Contact model operations
โ”‚   โ”œโ”€โ”€ email_logs/       # Email log model operations
โ”‚   โ”œโ”€โ”€ gmailtokens/      # Gmail token model operations
โ”‚   โ””โ”€โ”€ profileinfo/      # Profile model operations
โ”œโ”€โ”€ frontend/              # Web dashboard
โ”‚   โ”œโ”€โ”€ public/           # Static HTML files
โ”‚   โ”‚   โ””โ”€โ”€ index.html    # Main dashboard page
โ”‚   โ”œโ”€โ”€ src/              # JavaScript and CSS
โ”‚   โ”‚   โ””โ”€โ”€ app.js        # Frontend application logic
โ”‚   โ”œโ”€โ”€ Dockerfile        # Frontend container configuration
โ”‚   โ””โ”€โ”€ nginx.conf        # Nginx configuration
โ”œโ”€โ”€ gmail/                 # Gmail API integration
โ”‚   โ””โ”€โ”€ client.go         # Gmail OAuth and sending logic
โ”œโ”€โ”€ migrations/            # Database migration files
โ”‚   โ”œโ”€โ”€ 20250707_150303_profile_info.sql
โ”‚   โ”œโ”€โ”€ 20250708_161223_gmail_tokens.sql
โ”‚   โ”œโ”€โ”€ 20250708_192659_companies.sql
โ”‚   โ”œโ”€โ”€ 20250709_012642_contacts.sql
โ”‚   โ””โ”€โ”€ 20250709_014140_email_outreach.sql
โ”œโ”€โ”€ openai/                # OpenAI API integration
โ”‚   โ””โ”€โ”€ client.go         # OpenAI client for email generation
โ”œโ”€โ”€ storage/               # File storage management
โ”‚   โ”œโ”€โ”€ storage.go        # File upload and management
โ”‚   โ””โ”€โ”€ storage_test.go   # Storage tests
โ”œโ”€โ”€ utils/                 # Utility functions
โ”‚   โ””โ”€โ”€ helpers.go        # Common helper functions
โ”œโ”€โ”€ docker-compose.yml     # Docker services configuration
โ”œโ”€โ”€ Dockerfile            # Backend application container
โ”œโ”€โ”€ go.mod               # Go module dependencies
โ””โ”€โ”€ README.md            # This file

๐Ÿ”„ Usage Workflow

Complete Setup Process

  1. Initial Setup

    # Start services
    docker-compose up -d --build
    
    # Verify health
    curl http://localhost:8000/health
  2. Profile Configuration

    # Upload profile and resume
    curl -X POST http://localhost:8000/api/profile \
      -F "name=Your Name" \
      -F "email=your.email@example.com" \
      -F "phone=+1234567890" \
      -F "linkedin_url=https://linkedin.com/in/yourprofile" \
      -F "experience=5 years of software development..." \
      -F "skills=Go, Python, React, AWS..." \
      -F "summary=Experienced software engineer..." \
      -F "resume=@/path/to/your/resume.pdf"
  3. Gmail Authentication

    # Visit in browser to complete OAuth
    open http://localhost:8000/gmail-auth-initiate
  4. Access Dashboard

    # Open the web dashboard
    open http://localhost:3000

    The dashboard provides:

    • Email Logs Tab: View all sent emails with pagination and filtering
    • Companies & Contacts Tab: Browse companies and their associated contacts
    • System Config Display: Current targeting parameters
  5. Database Enrichment

    # Enrich with companies and contacts
    curl -X POST http://localhost:8000/api/enrich-database \
      -H "Content-Type: application/json" \
      -d '{"count_new_companies": 50, "max_contacts_per_company": 5}'
    
    # Backfill company details
    curl -X POST http://localhost:8000/api/backfill-company-details
  6. Start Email Campaign

    # Send initial outreach emails
    curl -X POST http://localhost:8000/api/send-few-initial-emails
    
    # Check logs via API or dashboard
    curl http://localhost:8000/api/logs
    # OR visit http://localhost:3000 and check Email Logs tab
  7. Follow-up Campaign

    # Send follow-up emails (after some time)
    curl -X POST http://localhost:8000/api/send-few-follow-up-emails

Monitoring and Management

# Check system status
curl http://localhost:8000/api/status

# View email logs via API
curl http://localhost:8000/api/email-logs?page=1&limit=20

# View companies via API
curl http://localhost:8000/api/companies

# Check database (direct SQL)
docker exec -it cold_emailer_db_1 psql -U coldemailer -d coldemailer

Or use the web dashboard at http://localhost:3000 for a visual interface to:

  • Browse email logs with pagination and filtering
  • Search and filter companies by name, industry, or website
  • View detailed contact information organized by company
  • Monitor system configuration and targeting parameters

๐Ÿ”’ Security & Best Practices

API Key Management

  • Store all API keys in .env file (never commit to git)
  • Use environment variables in production
  • Rotate keys regularly

Database Security

  • Use strong passwords for database
  • Implement proper connection pooling
  • Regular backups recommended

OAuth Security

  • Secure redirect URI configuration
  • Token refresh handling
  • Proper scope management for Gmail API

๐Ÿšจ Rate Limiting & Quotas

Apollo API

  • Respects Apollo's rate limits
  • Implements exponential backoff
  • Batches requests efficiently

OpenAI API

  • Configurable temperature and max tokens
  • Error handling for quota limits
  • Retry logic for transient failures

Gmail API

  • OAuth token refresh handling
  • Respects Gmail sending limits
  • Proper attachment handling

๐Ÿ› Troubleshooting

Common Issues

Database Connection Issues

# Check database status
docker-compose ps

# View database logs
docker-compose logs db

# Connect to database manually
docker exec -it cold_emailer_db_1 psql -U coldemailer -d coldemailer

Frontend Issues

# Check frontend container logs
docker-compose logs frontend

# Verify frontend is accessible
curl http://localhost:3000

# Check if API proxy is working
curl http://localhost:3000/api/companies

Gmail Authentication Issues

  • Verify redirect URI matches exactly in Google Cloud Console
  • Check OAuth scopes are properly configured
  • Ensure Gmail API is enabled in Google Cloud Console

API Key Issues

  • Verify all API keys are correctly set in .env
  • Check API key permissions and quotas
  • Test API keys independently

Migration Issues

# Generate new migration
go run cmd/server/main.go --generate-migration your_migration_name

# Check migration status in database
SELECT * FROM schema_migrations;

๐Ÿ“Š Monitoring & Logging

Log Levels

  • Error: API failures, database errors
  • Info: Successful operations, status updates
  • Debug: Detailed operation flow

Key Metrics to Monitor

  • Email generation success rate
  • Email sending success rate
  • API response times
  • Database connection health
  • File storage usage
  • Frontend dashboard usage

๐Ÿ”ฎ Future Enhancements

  • Web UI for campaign management
  • Advanced email templates
  • A/B testing for email content
  • Analytics dashboard with charts
  • Webhook support for status updates
  • Multi-user support
  • Email scheduling
  • CRM integrations
  • Real-time notifications
  • Advanced filtering and search
  • Export functionality

๐Ÿ“„ License

MIT License - see LICENSE file for details

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

๐Ÿ“ž Support

For issues and questions:

  • Create an issue in the GitHub repository
  • Check the troubleshooting section above
  • Review logs for detailed error information

Note: This system is designed for legitimate job application outreach. Please ensure compliance with applicable laws and email service provider terms of service when using this tool.

๐Ÿ”’ Security & Best Practices

API Key Management

  • Store all API keys in .env file (never commit to git)
  • Use environment variables in production
  • Rotate keys regularly

Database Security

  • Use strong passwords for database
  • Implement proper connection pooling
  • Regular backups recommended

OAuth Security

  • Secure redirect URI configuration
  • Token refresh handling
  • Proper scope management for Gmail API

๐Ÿšจ Rate Limiting & Quotas

Apollo API

  • Respects Apollo's rate limits
  • Implements exponential backoff
  • Batches requests efficiently

OpenAI API

  • Configurable temperature and max tokens
  • Error handling for quota limits
  • Retry logic for transient failures

Gmail API

  • OAuth token refresh handling
  • Respects Gmail sending limits
  • Proper attachment handling

๐Ÿ› Troubleshooting

Common Issues

Database Connection Issues

# Check database status
docker-compose ps

# View database logs
docker-compose logs db

# Connect to database manually
docker exec -it cold_emailer_db_1 psql -U coldemailer -d coldemailer

Gmail Authentication Issues

  • Verify redirect URI matches exactly in Google Cloud Console
  • Check OAuth scopes are properly configured
  • Ensure Gmail API is enabled in Google Cloud Console

API Key Issues

  • Verify all API keys are correctly set in .env
  • Check API key permissions and quotas
  • Test API keys independently

Migration Issues

# Generate new migration
go run cmd/server/main.go --generate-migration your_migration_name

# Check migration status in database
SELECT * FROM schema_migrations;

๐Ÿ“Š Monitoring & Logging

Log Levels

  • Error: API failures, database errors
  • Info: Successful operations, status updates
  • Debug: Detailed operation flow

Key Metrics to Monitor

  • Email generation success rate
  • Email sending success rate
  • API response times
  • Database connection health
  • File storage usage

๐Ÿ“„ License

MIT License - see LICENSE file for details

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

๐Ÿ“ž Support

For issues and questions:

  • Create an issue in the GitHub repository
  • Check the troubleshooting section above
  • Review logs for detailed error information

Note: This system is designed for legitimate job application outreach. Please ensure compliance with applicable laws and email service provider terms of service when using this tool.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors