8000 GitHub - R44VC0RP/inbound: email infrastructure for agent and indie devs
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

R44VC0RP/inbound

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Inbound Email System

A dynamic email receiving and processing system built with AWS SES, Lambda, and Next.js that allows you to programmatically manage email addresses and automatically process incoming emails.

πŸ“‹ Overview

Inbound.exon.dev enables you to:

  • Dynamically manage email addresses through your API
  • Automatically receive emails for managed domains using AWS SES
  • Process emails via Lambda with spam/virus filtering
  • Store emails in S3 temporarily (auto-deleted after 90 days)
  • Send real-time webhooks to your API when emails arrive
  • Retrieve full email content on-demand from S3

πŸ—οΈ System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Email Sender  │───▢│   AWS SES       │───▢│   S3 Bucket     β”‚
β”‚                 β”‚    β”‚ (Spam/Virus     β”‚    β”‚ (Email Storage) β”‚
β”‚ test@exon.dev   β”‚    β”‚  Filtering)     β”‚    β”‚                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                        β”‚
                                                        β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Your API      │◀───│   Lambda        │◀───│   SES Trigger   β”‚
β”‚ (Webhook        β”‚    β”‚ (Email          β”‚    β”‚                 β”‚
β”‚  Endpoint)      β”‚    β”‚  Processor)     β”‚    β”‚                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                       β”‚
         β–Ό                       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Next.js       β”‚    β”‚   CloudWatch    β”‚
β”‚ (Dashboard)     β”‚    β”‚ (Logs/Metrics)  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“ Project Structure

Core Infrastructure Files

inbound.exon.dev/
β”œβ”€β”€ πŸ“ aws/                          # AWS Infrastructure
β”‚   └── πŸ“ cdk/                      # CDK Infrastructure as Code
β”‚       β”œβ”€β”€ πŸ“„ lib/inbound-email-stack.ts  # Main CDK stack definition
β”‚       β”œβ”€β”€ πŸ“„ bin/inbound-email-cdk.ts    # CDK app entry point
β”‚       β”œβ”€β”€ πŸ“„ package.json               # CDK dependencies
β”‚       └── πŸ“„ cdk.json                   # CDK configuration
β”‚
β”œβ”€β”€ πŸ“ lambda/                       # Lambda Functions
β”‚   └── πŸ“ email-processor/          # Email processing Lambda
β”‚       β”œβ”€β”€ πŸ“„ index.ts              # Lambda handler entry point
β”‚       β”œβ”€β”€ πŸ“„ package.json          # Lambda dependencies
β”‚       β”œβ”€β”€ πŸ“„ tsconfig.json         # TypeScript config
β”‚       └── πŸ“ dist/                 # Compiled Lambda code
β”‚
β”œβ”€β”€ πŸ“ lib/                          # Shared Libraries
β”‚   └── πŸ“„ aws-ses.ts                # Email processing library
β”‚
β”œβ”€β”€ πŸ“ scripts/                      # Deployment Scripts
β”‚   β”œβ”€β”€ πŸ“„ deploy-email-system.ts    # Full deployment script
β”‚   β”œβ”€β”€ πŸ“„ quick-deploy.ts           # Quick deployment script
β”‚   └── πŸ“„ test-deployment.ts        # Deployment verification
β”‚
β”œβ”€β”€ πŸ“ docs/                         # Documentation
β”‚   β”œβ”€β”€ πŸ“„ DEPLOYMENT_GUIDE.md       # Complete deployment guide
β”‚   β”œβ”€β”€ πŸ“„ LAMBDA_DEPLOYMENT.md      # Lambda-specific setup
β”‚   └── πŸ“„ DYNAMIC_EMAIL_MANAGEMENT.md # API integration guide
β”‚
└── πŸ“ app/                          # Next.js Application
    β”œβ”€β”€ πŸ“ (main)/                   # Main app routes
    β”œβ”€β”€ πŸ“ api/                      # API endpoints
    └── πŸ“ components/               # React components

Key Configuration Files

  • package.json - Main project dependencies and deployment scripts
  • .env - Environment variables (API keys, AWS config)
  • aws/cdk/lib/inbound-email-stack.ts - Infrastructure definition
  • lambda/email-processor/index.ts - Email processing logic

πŸš€ Quick Start

Prerequisites

# 1. Install dependencies
bun install

# 2. Configure AWS CLI
aws configure
# Enter: Access Key ID, Secret Access Key, Region (us-east-2)

# 3. Bootstrap CDK (first time only)
cd aws/cdk && bun run cdk bootstrap

Environment Setup

# Create .env file with your configuration
export SERVICE_API_URL="https://inbound.exon.dev"
export SERVICE_API_KEY="your-secret-api-key"
export EMAIL_DOMAINS="exon.dev,yourdomain.com"
export AWS_REGION="us-east-2"

πŸ“¦ Deployment Process

New Enhanced Deployment (Recommended)

The CDK stack now automatically outputs all required environment variables:

cd aws/cdk
npm install
./deploy.sh  # Full deployment with environment variable extraction

This will deploy the infrastructure and display:

πŸŽ‰ DEPLOYMENT COMPLETE!

πŸ“ Add these environment variables to your .env file:

# AWS Configuration for Email Processing
S3_BUCKET_NAME=inbound-emails-123456789012-us-west-2
AWS_ACCOUNT_ID=123456789012
LAMBDA_FUNCTION_NAME=inbound-email-processor
AWS_REGION=us-west-2

# Make sure you also have these (from your AWS credentials):
# AWS_ACCESS_KEY_ID=your_access_key_here
# AWS_SECRET_ACCESS_KEY=your_secret_key_here

Build Process Flow

1. Lambda Build    β†’  2. CDK Synthesis  β†’  3. AWS Deployment  β†’  4. Verification
   β”œβ”€ TypeScript      β”œβ”€ Infrastructure     β”œβ”€ CloudFormation    β”œβ”€ Stack Status
   β”œβ”€ Dependencies    β”œβ”€ Asset Bundling     β”œβ”€ S3 Bucket         β”œβ”€ Lambda Test
   └─ Dist Output     └─ Template Gen       β”œβ”€ Lambda Function   β”œβ”€ SES Rules
                                            β”œβ”€ SES Rules         └─ Monitoring
                                            └─ IAM Permissions

Deployment Commands

Option 1: Quick Deployment (Recommended)

# Deploy everything with defaults
bun run deploy:quick

# Deploy with custom configuration
SERVICE_API_URL=https://your-domain.com \
EMAIL_DOMAINS=yourdomain.com \
bun run deploy:quick

Option 2: Step-by-Step Deployment

# 1. Build Lambda function only
bun run deploy:lambda

# 2. Deploy CDK infrastructure only
SERVICE_API_URL=https://your-domain.com bun run deploy:cdk

# 3. Deploy with full configuration options
bun run deploy:email --service-api-url https://your-domain.com \
                     --email-domains exon.dev,example.com \
                     --aws-region us-east-2

Option 3: Manual Build Process

# 1. Build Lambda function
cd lambda/email-processor
bun install
bun run build

# 2. Build and deploy CDK
cd ../../aws/cdk
bun install
bun run build
SERVICE_API_URL=https://your-domain.com bun run cdk deploy

πŸ§ͺ Testing & Verification

1. Deployment Verification

# Test the deployment
bun run test:deployment

# Test with specific region
AWS_REGION=us-east-2 bun run test:deployment

Expected Output:

πŸ§ͺ Testing Email System Deployment

1️⃣ Testing AWS credentials...
βœ… AWS Account: 375612485665

2️⃣ Checking CloudFormation stack...
βœ… Stack Status: CREATE_COMPLETE

3️⃣ Testing Lambda function...
βœ… Lambda State: Active
βœ… Lambda Runtime: nodejs18.x
βœ… Lambda Memory: 512MB

4️⃣ Testing S3 bucket...
βœ… Email bucket found: inbound-emails-375612485665-us-east-2

5️⃣ Testing SES receipt rules...
βœ… Receipt rule set found with 1 rules

βœ… Deployment test completed!

2. Domain Configuration

Verify Domain in AWS SES

# Verify your domain
aws ses verify-domain-identity --domain exon.dev --region us-east-2

# Check verification status
aws ses get-identity-verification-attributes --identities exon.dev --region us-east-2

Configure DNS Records

Add these DNS records to your domain:

MX Record:

Type: MX
Name: @
Value: 10 inbound-smtp.us-east-2.amazonaws.com
TTL: 300

TXT Record (for domain verification):

Type: TXT
Name: @ 
Value: [Value from AWS SES verification]
TTL: 300

3. Email Testing

Send Test Email

# Send email to any address at your domain
echo "Test email body" | mail -s "Test Subject" test@yourdomain.com

Monitor Processing

# Watch Lambda logs in real-time
aws logs tail /aws/lambda/inbound-email-processor --follow --region us-east-2

# Check recent Lambda invocations
aws logs describe-log-streams --log-group-name /aws/lambda/inbound-email-processor --region us-east-2

# View S3 bucket contents
aws s3 ls s3://inbound-emails-375612485665-us-east-2/emails/ --recursive

πŸ”§ Development Workflow

Local Development

# Start Next.js development server
bun run dev

# Run in development mode with turbopack
bun run dev --turbo

Making Changes

Update Lambda Function

# 1. Edit lambda/email-processor/index.ts
# 2. Build and deploy
bun run deploy:lambda

Update Infrastructure

# 1. Edit aws/cdk/lib/inbound-email-stack.ts
# 2. Deploy changes
bun run deploy:cdk

Update Email Processing Logic

# 1. Edit lib/aws-ses.ts
# 2. Rebuild Lambda
cd lambda/email-processor && bun run build
# 3. Deploy
bun run deploy:lambda

πŸ“Š Monitoring & Debugging

CloudWatch Logs

# View Lambda logs
aws logs tail /aws/lambda/inbound-email-processor --follow --region us-east-2

# Search for errors
aws logs filter-log-events --log-group-name /aws/lambda/inbound-email-processor \
  --filter-pattern "ERROR" --region us-east-2

# View specific time range
aws logs filter-log-events --log-group-name /aws/lambda/inbound-email-processor \
  --start-time 1640995200000 --end-time 1641081600000 --region us-east-2

AWS Console Monitoring

  • Lambda: Monitor invocations, duration, errors
  • S3: Check email storage and lifecycle
  • SES: View receipt metrics and bounce rates
  • CloudWatch: Set up alarms for errors and performance

Debug Commands

# Check AWS configuration
aws sts get-caller-identity

# List CloudFormation stacks
aws cloudformation list-stacks --region us-east-2

# Check Lambda function details
aws lambda get-function --function-name inbound-email-processor --region us-east-2

# Test Lambda manually
aws lambda invoke --function-name inbound-email-processor \
  --payload file://test-event.json response.json --region us-east-2

πŸ”„ Maintenance & Updates

Update Dependencies

# Update main project
bun update

# Update Lambda dependencies
cd lambda/email-processor && bun update

# Update CDK dependencies
cd aws/cdk && bun update

Cleanup Resources

# Destroy all AWS resources
cd aws/cdk && bun run cdk destroy

# Clean build artifacts
rm -rf lambda/email-processor/dist
rm -r
6D47
f aws/cdk/cdk.out

🚨 Troubleshooting

Common Issues

Docker Not Running (CDK Deployment)

# Start Docker Desktop
open -a Docker

# Or use pre-built Lambda approach (already configured)
bun run deploy:quick

TypeScript Compilation Errors

# Check Lambda TypeScript config
cd lambda/email-processor
bun run build

# Fix import paths if needed

AWS Permissions

# Verify AWS credentials
aws sts get-caller-identity

# Check IAM permissions for SES, S3, Lambda, CloudFormation

Email Not Received

  1. Check MX records: dig MX yourdomain.com
  2. Verify domain in SES console
  3. Check SES sandbox mode
  4. Monitor CloudWatch logs

Debug Checklist

  • AWS CLI configured and working
  • Domain verified in AWS SES
  • MX records pointing to AWS SES
  • Lambda function deployed and active
  • S3 bucket created with proper permissions
  • SES receipt rules configured
  • CloudWatch logs showing activity

πŸ“š Additional Resources

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

Ready to receive emails? Run bun run deploy:quick and follow the setup steps! πŸŽ‰

About

email infrastructure for agent and indie devs

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages

0