Email_Bulk Svelte Themes

Email_bulk

Full-stack bulk email sender with SvelteKit frontend and Hono backend. Features secure authentication, SMTP configuration management, Excel file uploads, rich text editor, variable personalization, and comprehensive reporting. Built with MongoDB Atlas, TypeScript, and includes Swagger UI for API testing.

šŸš€ Bulk Email Sender - SvelteKit + MongoDB

A modern, full-stack bulk email sender application built with SvelteKit (frontend) and Hono (backend) using MongoDB Atlas for data persistence.

āœ… Project Status: COMPLETED

All assignment objectives have been successfully completed!

Current Tech Stack

  • Backend: Hono + Node.js (migrated from Bun)
  • Frontend: SvelteKit + TypeScript
  • Database: MongoDB Atlas (migrated from SQLite)
  • Authentication: Argon2 password hashing with session tokens
  • Email: Nodemailer with SMTP (ready to implement)

šŸŽÆ Completed Features

āœ… 1. SvelteKit Frontend

  • āœ… Modern, clean UI with gradient design
  • āœ… Responsive layout (mobile, tablet, desktop)
  • āœ… Client-side validation and error handling
  • āœ… Toast notifications for user feedback
  • āœ… Protected routes with authentication

āœ… 2. Authentication System

  • āœ… User registration with validation
  • āœ… Secure login with Argon2 hashing
  • āœ… Session management with HTTP-only cookies
  • āœ… Auto-redirect for protected routes
  • āœ… Logout functionality

āœ… 3. SMTP Configuration

  • āœ… Add/Edit/Delete SMTP configs
  • āœ… Multiple SMTP accounts per user
  • āœ… Set default configuration
  • āœ… Secure password storage in MongoDB

āœ… 4. Dashboard

  • āœ… Statistics cards (Total, Success Rate, Failed, Scheduled)
  • āœ… Quick action buttons
  • āœ… User profile display
  • āœ… Navigation sidebar

āœ… 5. Reports & Analytics

  • āœ… Email logs table
  • āœ… Statistics display
  • āœ… Clear logs functionality
  • āœ… Status badges (Sent/Failed)

āœ… 6. Database Migration

  • āœ… Migrated from SQLite to MongoDB Atlas
  • āœ… User management
  • āœ… Session storage
  • āœ… SMTP configurations
  • āœ… Email logs
  • āœ… Automatic collection creation

āœ… 8. Email Sending (NEW!)

  • āœ… Excel file upload for contacts
  • āœ… Rich text editor (Quill) for email composition
  • āœ… Variable replacement ({{FirstName}}, {{LastName}}, etc.)
  • āœ… Delay configuration between emails
  • āœ… Bulk email sending with progress tracking
  • āœ… Email logs saved to MongoDB
  • āœ… Migrated from Bun to Node.js
  • āœ… Updated all dependencies
  • āœ… Removed Bun-specific code
  • āœ… CORS configured for SvelteKit
  • āœ… API routes working

šŸ“¦ Installation & Setup

Prerequisites

  • Node.js (v18 or higher)
  • MongoDB Atlas account (or local MongoDB)
  • npm or yarn

1. Clone Repository

git clone <repository-url>
cd assignment-main/assignment-main

2. Backend Setup

# Install dependencies
npm install

# Configure environment
cp .env.example .env
# Edit .env with your MongoDB Atlas credentials

3. Frontend Setup

cd frontend
npm install

4. Environment Configuration

Backend (.env):

# MongoDB Atlas
MONGODB_URI=mongodb+srv://<username>:<password>@<cluster>.mongodb.net/?appName=Email
MONGODB_DB_NAME=bulk_email_sender

# Server
PORT=3000
SESSION_SECRET=your-secure-random-string

# SMTP (Optional - users can configure their own)
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
[email protected]
SMTP_PASS=your-app-password

Frontend (frontend/.env):

VITE_API_URL=http://localhost:3000

šŸš€ Running the Application

Start Backend

npm run dev

Backend runs on: http://localhost:3000

Start Frontend (in new terminal)

cd frontend
npm run dev

Frontend runs on: http://localhost:5173


šŸ“± Using the Application

1. Register Account

  • Open http://localhost:5173
  • Click "Register here"
  • Enter name, email, password (min 6 characters)
  • Click "Register"

2. Configure SMTP

  • Go to "āš™ļø SMTP Config"
  • Click "+ Add New Config"
  • Enter SMTP details:
    • Gmail: smtp.gmail.com:587 (use App Password)
    • Outlook: smtp-mail.outlook.com:587
    • Custom: Your SMTP server details
  • Click "Save Configuration"

3. Send Emails

  • Go to "šŸ“§ Send Emails"
  • Upload Excel file with contacts (Email, FirstName, LastName, Company columns)
  • Enter email subject (use {{FirstName}}, {{Company}} for personalization)
  • Compose email using rich text editor
  • Set delay between emails (default: 2 seconds)
  • Click "Send Emails"
  • View progress in Reports

4. View Reports

  • Go to "šŸ“ˆ Reports"
  • View email logs and statistics
  • Export or clear logs

šŸ—„ļø Database Schema

Collections (Auto-created)

users

{
  _id: ObjectId,
  email: String (unique),
  name: String,
  passwordHash: String,
  createdAt: Date,
  lastLogin: Date,
  isActive: Boolean
}

sessions

{
  _id: ObjectId,
  userId: ObjectId,
  token: String (unique),
  expiresAt: Date,
  createdAt: Date
}

smtpConfigs

{
  _id: ObjectId,
  userId: ObjectId,
  name: String,
  host: String,
  port: Number,
  secure: Boolean,
  user: String,
  pass: String,
  fromEmail: String,
  fromName: String,
  isDefault: Boolean,
  createdAt: Date,
  updatedAt: Date
}

emailLogs

{
  _id: ObjectId,
  userId: ObjectId,
  email: String,
  status: String,
  message: String,
  timestamp: Date,
  subject: String
}

šŸ“Š API Endpoints

Authentication

  • POST /auth/register - Register new user
  • POST /auth/login - Login user
  • POST /auth/logout - Logout user
  • GET /auth/me - Get current user

SMTP Configuration

  • GET /config/smtp - Get all user SMTP configs
  • POST /config/smtp - Create new SMTP config
  • PUT /config/smtp/:id - Update SMTP config
  • DELETE /config/smtp/:id - Delete SMTP config
  • POST /config/smtp/:id/default - Set as default

Email Sending

  • POST /send - Send bulk emails with Excel file
  • GET /send/batch-status - Get batch status

Reports

  • GET /report - Get email logs and stats
  • DELETE /report/clear - Clear all logs

Dashboard

  • GET /dashboard/poll-status - Check polling status
  • GET /dashboard/stats - Get dashboard statistics

API Documentation

  • GET /api-docs - Swagger UI for interactive API testing
  • GET /swagger.json - OpenAPI specification

šŸŽØ Project Structure

assignment-main/
ā”œā”€ā”€ src/                          # Backend
│   ā”œā”€ā”€ app.ts                   # Main app entry
│   ā”œā”€ā”€ types.ts                 # TypeScript types
│   ā”œā”€ā”€ middleware/
│   │   └── auth.ts             # Auth middleware
│   ā”œā”€ā”€ routes/
│   │   ā”œā”€ā”€ auth.ts             # Auth routes
│   │   ā”œā”€ā”€ config.ts           # SMTP config routes
│   │   ā”œā”€ā”€ send.ts             # Email sending routes
│   │   ā”œā”€ā”€ report.ts           # Reports routes
│   │   └── dashboard.ts        # Dashboard routes
│   └── services/
│       └── mongoDatabase.ts    # MongoDB service
ā”œā”€ā”€ frontend/                    # SvelteKit Frontend
│   ā”œā”€ā”€ src/
│   │   ā”œā”€ā”€ routes/
│   │   │   ā”œā”€ā”€ +layout.svelte
│   │   │   ā”œā”€ā”€ +page.svelte
│   │   │   ā”œā”€ā”€ login/
│   │   │   ā”œā”€ā”€ register/
│   │   │   ā”œā”€ā”€ dashboard/
│   │   │   ā”œā”€ā”€ send/
│   │   │   ā”œā”€ā”€ config/
│   │   │   └── reports/
│   │   └── lib/
│   │       ā”œā”€ā”€ api/            # API client
│   │       ā”œā”€ā”€ stores/         # Svelte stores
│   │       └── components/     # UI components
│   └── static/
ā”œā”€ā”€ uploads/                     # Uploaded files
ā”œā”€ā”€ logs/                        # Email logs
ā”œā”€ā”€ .env                         # Environment variables
└── package.json

šŸ”’ Security Features

  • āœ… Argon2 password hashing
  • āœ… HTTP-only session cookies
  • āœ… CORS protection
  • āœ… Input validation
  • āœ… MongoDB injection prevention
  • āœ… Secure session management

šŸ› Troubleshooting

Port Already in Use

# Kill process on port 3000
netstat -ano | findstr :3000
taskkill /F /PID <PID>

MongoDB Connection Failed

  • Check MongoDB Atlas connection string
  • Verify IP whitelist in Atlas
  • Ensure username/password are correct

CORS Errors

  • Verify frontend URL in backend CORS config
  • Check credentials: 'include' in API calls

šŸŽ‰ Success Indicators

āœ… Backend running on Node.js with MongoDB Atlas āœ… Frontend running on SvelteKit āœ… User authentication working āœ… SMTP configuration management working āœ… Email sending with Excel upload working āœ… Rich text editor (Quill) integrated āœ… Variable replacement working āœ… Reports displaying correctly āœ… Responsive design āœ… No old frontend code (public/ folder removed) āœ… All API endpoints functional āœ… Swagger UI available at /api-docs for API testing

šŸ“ What's Next (Optional Enhancements)

  1. Email scheduling for future delivery
  2. Batch processing with configurable batch sizes
  3. Email templates library
  4. Advanced analytics and charts
  5. Export reports as CSV/PDF

šŸ“„ License

MIT License


Built with ā¤ļø using SvelteKit, Hono, and MongoDB Atlas

Top categories

Loading Svelte Themes