Skip to content

AI Invoice Mailer

Beginner
ai email finance automation frontend

Generate professional invoices with AI and send them to clients via SMTP email. Manage clients, auto-populate invoice fields, and deliver polished results in one workflow.

AI Invoice Mailer is a full-stack automation that combines AI text generation with SMTP email delivery to produce and send professional invoices with minimal effort.

What it does

  • Client management : Save and list clients with save-client and list-clients habits
  • AI invoice generation : Uses OpenAI to auto-fill line items, descriptions, and totals based on a short prompt
  • Email delivery : Sends the finished invoice directly to the client via SMTP using credentials stored in .env

Environment variables (.env / keyring on apps)

VariablePurpose
HABITS_OPENAI_API_KEYOpenAI API key for AI-powered invoice content generation
HABITS_SMTP_HOSTSMTP server hostname (e.g. smtp.gmail.com)
HABITS_SMTP_PORTSMTP port (typically 587 for STARTTLS)
HABITS_SMTP_USERSMTP login username / email address
HABITS_SMTP_PASSWORDSMTP password or app-specific password
HABITS_EMAIL_FROMDisplay name and address used as the sender

How to set up

  1. Copy .env.example to .env and fill in your credentials.
  2. On desktop/mobile apps, the same keys are stored securely in the system keyring.
  3. Run save-client to add a client, then generate-invoice to create and send an invoice.

Tech stack

  • habits framework for workflow orchestration
  • OpenAI for natural-language invoice generation
  • SMTP (Nodemailer-compatible) for email delivery
  • Frontend habit for interactive client/invoice management UI

Run Your .habit File

Run on Mobile

  • [ ] Download the Cortex App from store or the downloads page
  • [ ] Open the Cortex App on your device
  • [ ] Tap "Open Habit" or "+" button
  • [ ] Select your .habit file from your device storage
  • [ ] The habit will be loaded and ready to run

Run on Desktop

  • [ ] Download the Cortex App for your platform from the downloads page
  • [ ] Install and open the Cortex App
  • [ ] Click "Open Habit" or drag & drop your .habit file
  • [ ] The habit will be loaded and ready to run
  • [ ] Optional: Place a .env file in the same directory as your .habit file to override environment variables

Run on Server

Run your .habit file as a server using the Cortex CLI:

bash
# Install and run in one command
npx @ha-bits/cortex --config ./your-app.habit
  • [ ] Make sure Node.js 20+ is installed
  • [ ] Run the command above with your .habit file path
  • [ ] Server will start on the specified port (default: 3000)
  • [ ] Access the app at http://localhost:3000
  • [ ] Optional: Place a .env file next to your .habit file - it will automatically override any embedded environment variables

Run Serverless

For serverless or containerized deployments, we recommend using Docker:

bash
# Using Docker (recommended for serverless)
docker run -p 3000:3000 -v $(pwd)/your-app.habit:/app/habit.habit \
  node:20-alpine npx @ha-bits/cortex --config /app/habit.habit --host 0.0.0.0

Or create a Dockerfile:

dockerfile
FROM node:20-alpine
WORKDIR /app
COPY your-app.habit ./
COPY .env ./ # Optional: include environment variables
RUN npm install -g @ha-bits/cortex
EXPOSE 3000
CMD ["cortex", "--config", "./your-app.habit", "--host", "0.0.0.0"]
  • [ ] Create a Dockerfile or use the Docker run command above
  • [ ] Deploy to your preferred cloud provider (AWS, GCP, Azure, etc.)
  • [ ] Configure environment variables via your cloud provider's secrets management
  • [ ] Set up health checks at /habits/base/api endpoint

Workflow Visualization

Requirements

  • OPENAI_API_KEY (OpenAI API key)
  • SMTP_HOST (SMTP server hostname)
  • SMTP_PORT (SMTP port)
  • SMTP_USER (SMTP login username / email address)
  • SMTP_PASSWORD (SMTP password or app-specific password)
  • EMAIL_FROM (Display name and address used as the sender)

Quick Start

Run using the Habits CLI wrapper, recommended if you develop local Habits

# First, download the example files
npx habits@latest cortex --config ./ai-invoice-mailer/stack.yaml

Get in touch

Want this habit running in your environment?

This habit is a starting point. Tell us about your stack and we'll help you get it working exactly the way your team needs.

Released under the AGPL-3.0 License.