Sign inSign up

carfdev/carfdev-emailsvc

By carfdev

β€’Updated 12 months ago

Event-driven email microservice. NATS + Resend integration. Multi-arch. Minimal footprint.

Image
0

316

carfdev/carfdev-emailsvc repository overview

⁠Email Service for NATS-based Microservices

A lightweight, production-ready email microservice that integrates seamlessly with NATS messaging and Resend API. Built with Go for high performance and minimal resource footprint.

β πŸš€ Quick Start

docker run -d \
  --name emailsvc \
  -e NATS_URL=nats://your-nats-server:4222 \
  -e EMAIL_KEY=re_your_resend_api_key \
  -e [email protected] \
  -e [email protected] \
  carfdev/carfdev-emailsvc:latest

⁠✨ Features

  • Event-Driven Architecture: Listens to NATS subjects for asynchronous email processing
  • Resend Integration: Professional email delivery with high deliverability rates
  • Multi-Architecture: Native support for linux/amd64 and linux/arm64
  • Minimal Footprint: ~10MB image size using scratch-based build
  • Production Ready: Graceful shutdown, structured logging, and error handling
  • HTML Templates: Beautiful, responsive email designs included

β πŸ“‹ Environment Variables

VariableDescriptionRequiredDefault
NATS_URLNATS server connection URLNonats://localhost:4222
EMAIL_KEYResend API keyYes-
EMAIL_FROMSender email addressNo[email protected]
EMAIL_ADMINAdmin email for notificationsNo[email protected]
SERVICE_NAMEService identifierNoemailsvc
ENVEnvironment (dev/prod)Nodev

β πŸ“‘ NATS Subjects

⁠email.send_contact

Send contact form emails to administrators.

Request:

{
  "FirstName": "John",
  "LastName": "Doe",
  "Email": "[email protected]",
  "CompanyName": "Acme Corp",
  "ProjectType": "Web Development",
  "Budget": "$10,000 - $25,000",
  "Message": "We need help with..."
}

Response:

{
  "data": {
    "status": 200,
    "message": "Email sent, ID: abc123xyz"
  }
}

⁠🐳 Docker Compose Example

version: '3.8'
services:
  nats:
    image: nats:latest
    ports:
      - "4222:4222"

  emailsvc:
    image: carfdev/carfdev-emailsvc:latest
    environment:
      - NATS_URL=nats://nats:4222
      - EMAIL_KEY=${RESEND_API_KEY}
      - [email protected]
      - [email protected]
      - ENV=production
    depends_on:
      - nats
    restart: unless-stopped

⁠☸️ Kubernetes Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: emailsvc
spec:
  replicas: 2
  selector:
    matchLabels:
      app: emailsvc
  template:
    metadata:
      labels:
        app: emailsvc
    spec:
      containers:
      - name: emailsvc
        image: carfdev/carfdev-emailsvc:latest
        env:
        - name: NATS_URL
          value: "nats://nats-service:4222"
        - name: EMAIL_KEY
          valueFrom:
            secretKeyRef:
              name: email-secrets
              key: resend-api-key
        - name: EMAIL_FROM
          value: "[email protected]"
        - name: EMAIL_ADMIN
          value: "[email protected]"
        resources:
          requests:
            memory: "32Mi"
            cpu: "50m"
          limits:
            memory: "64Mi"
            cpu: "100m"

β πŸ”’ Security

  • Minimal attack surface with scratch-based image
  • No sensitive data in logs
  • TLS certificate verification included
  • Environment-based secrets management
  • Strict JSON validation to prevent injection

β πŸ“Š Performance

  • Memory: ~15MB base footprint
  • Throughput: 1000+ messages/second per instance
  • Latency: <100ms message processing
  • Image Size: ~10MB compressed

β πŸ“ License

MIT License - see repository for details

β πŸ‘¨β€πŸ’» Author

carfdev - Building cloud-native microservices


Tags: email, microservice, nats, golang, resend, docker, kubernetes, cloud-native

Tag summary

Content type

Image

Digest

sha256:634c081bc…

Size

5.4 MB

Last updated

12 months ago

docker pull carfdev/carfdev-emailsvc