Automatically translate English AI newsletters to Romanian using DeepL API and AWS Lambda.
This system monitors incoming email newsletters, extracts the content, translates it from English to Romanian using DeepL's high-quality translation API, and emails the result back to you.
Architecture:
Newsletter Email → Gmail Forwarding → Webhook → AWS Lambda → DeepL API → Email Back
Key Features:
- ✅ Automatic email processing via webhook
- ✅ High-quality EN→RO translation with DeepL
- ✅ Smart HTML parsing (removes footers, unsubscribe links)
- ✅ Includes both translated and original text
- ✅ Serverless architecture (AWS Lambda)
- ✅ Cost-effective: $0/month for typical usage (30 newsletters/month)
| Component | Service | Monthly Cost |
|---|---|---|
| Email Webhook | CloudMailin Free / SendGrid | $0 |
| Translation | DeepL API Free Tier | $0 (up to 500k chars) |
| Email Sending | AWS SES | $0 (free tier: 62k emails/month) |
| Lambda Execution | AWS Lambda | $0 (free tier: 1M requests) |
| TOTAL | $0/month |
For 30 newsletters/month (~5,000 words each = 200k characters), you'll stay well within free tiers.
- AWS Account (for Lambda and SES)
- DeepL API Account (free tier available)
- Gmail Account (or any email provider that supports forwarding)
- Email Webhook Service (CloudMailin free tier or SendGrid)
- Go to DeepL API
- Sign up for the DeepL API Free plan
- 500,000 characters/month free
- No credit card required
- Get your Authentication Key
- Will end with
:fxfor free tier - Example:
abc123def-456-789-ghi:fx
- Will end with
- Save this key - you'll need it later
# Using AWS CLI
aws ses verify-email-identity --email-address [email protected]Or via AWS Console:
- Go to AWS SES Console → Verified Identities
- Click Create Identity
- Select Email Address
- Enter your email and click Create Identity
- Check your inbox and click the verification link
By default, SES is in Sandbox Mode (can only send to verified addresses). For production use:
- In SES Console, click Account Dashboard
- Click Request production access
- Fill out the form explaining your use case
- Approval usually takes 24-48 hours
For testing: Just verify both sender and recipient emails.
# Clone this repository
git clone <your-repo-url>
cd newsletter-translator
# Run deployment script
./deploy.shThis creates newsletter-translator-lambda.zip containing:
lambda_function.py(main code)- All Python dependencies (requests library)
Option A: Using AWS Console
-
Go to AWS Lambda Console
-
Click Create function
-
Choose Author from scratch
-
Configure:
- Function name:
newsletter-translator - Runtime: Python 3.11
- Architecture: x86_64
- Function name:
-
Click Create function
-
Upload deployment package:
- In Code tab, click Upload from → .zip file
- Upload
newsletter-translator-lambda.zip - Click Save
-
Configure function:
- Timeout: 60 seconds (Configuration → General configuration → Edit)
- Memory: 512 MB
Option B: Using AWS CLI
# Create IAM role first (if not exists)
aws iam create-role \
--role-name lambda-newsletter-translator-role \
--assume-role-policy-document '{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": {"Service": "lambda.amazonaws.com"},
"Action": "sts:AssumeRole"
}]
}'
# Attach policies
aws iam attach-role-policy \
--role-name lambda-newsletter-translator-role \
--policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
aws iam attach-role-policy \
--role-name lambda-newsletter-translator-role \
--policy-arn arn:aws:iam::aws:policy/AmazonSESFullAccess
# Create function
aws lambda create-function \
--function-name newsletter-translator \
--runtime python3.11 \
--role arn:aws:iam::YOUR_ACCOUNT_ID:role/lambda-newsletter-translator-role \
--handler lambda_function.lambda_handler \
--zip-file fileb://newsletter-translator-lambda.zip \
--timeout 60 \
--memory-size 512In Lambda Console → Configuration → Environment variables → Edit
Add these variables:
| Key | Value | Example |
|---|---|---|
DEEPL_API_KEY |
Your DeepL API key | abc123-456-789:fx |
RECIPIENT_EMAIL |
Where to send translations | [email protected] |
SENDER_EMAIL |
SES verified sender address | [email protected] |
AWS_REGION |
AWS region for SES | us-east-1 |
- Go to API Gateway Console
- Click Create API → REST API → Build
- Configure:
- API name:
newsletter-webhook - Endpoint Type: Regional
- API name:
- Click Create API
-
Click Actions → Create Resource
- Resource Name:
translate - Resource Path:
/translate
- Resource Name:
-
Click Create Resource
-
With
/translateselected, click Actions → Create Method → POST -
Configure:
- Integration type: Lambda Function
- Lambda Function:
newsletter-translator - Use Lambda Proxy integration: ✅ Check this
-
Click Save → OK
- Click Actions → Deploy API
- Deployment stage: New Stage →
prod - Click Deploy
- Copy the Invoke URL (e.g.,
https://abc123.execute-api.us-east-1.amazonaws.com/prod)
Your webhook URL is: https://abc123.execute-api.us-east-1.amazonaws.com/prod/translate
You need a service that converts incoming emails to HTTP POST requests.
- Go to CloudMailin
- Sign up (free tier: 10,000 emails/month)
- Click Create Address
- Configure:
- Target URL:
https://your-api-gateway-url/prod/translate - HTTP Format: JSON
- Target URL:
- Copy your CloudMailin email address (e.g.,
[email protected])
- Go to SendGrid
- Sign up (free tier: 100 emails/day)
- Go to Settings → Inbound Parse
- Click Add Host & URL
- Configure:
- Domain: Use SendGrid's domain or your own
- URL:
https://your-api-gateway-url/prod/translate
- Get your inbound email address
See AWS SES Email Receiving Guide
Now set up Gmail to automatically forward newsletters to the webhook email.
- In Gmail, click the gear icon → See all settings
- Go to Filters and Blocked Addresses tab
- Click Create a new filter
- Configure filter criteria (example):
From: [email protected] OR From: [email protected] OR Subject: (AI Weekly OR AI Newsletter) - Click Create filter
- Check Forward it to → Enter CloudMailin/SendGrid address
- Click Create filter
When you receive a newsletter:
- Open the email
- Click More (⋮) → Forward
- Send to your webhook email address (CloudMailin/SendGrid)
- Install dependencies:
pip install -r requirements.txt
pip install python-dotenv # For loading .env file- Create
.envfile (copy from.env.example):
cp .env.example .env- Edit
.envwith your credentials:
DEEPL_API_KEY=your-key-here:fx
RECIPIENT_EMAIL=[email protected]
SENDER_EMAIL=[email protected]
AWS_REGION=us-east-1- Run test script:
python test_local.pyThis will:
- Process a sample AI newsletter
- Translate it to Romanian
- Send it to your email
curl -X POST https://your-api-gateway-url/prod/translate \
-H "Content-Type: application/json" \
-d '{
"subject": "Test Newsletter",
"from": "[email protected]",
"html": "<html><body><h1>Test</h1><p>This is a test newsletter about AI and machine learning.</p></body></html>"
}'Expected response:
{
"message": "Newsletter translated and sent successfully",
"original_length": 65,
"translated_length": 72
}- Send a test email to your CloudMailin/SendGrid address
- Check CloudWatch Logs:
aws logs tail /aws/lambda/newsletter-translator --follow
- Check your inbox for the translated email
The translated newsletter will be sent to your RECIPIENT_EMAIL with:
Subject: [RO] Original Newsletter Subject
Body:
NEWSLETTER TRADUS (EN → RO)
============================================================
Subiect original: AI Weekly Newsletter - Dec 2024
============================================================
TRADUCERE ROMÂNĂ:
============================================================
[Romanian translation here...]
============================================================
TEXT ORIGINAL (ENGLEZĂ):
============================================================
[Original English text here...]
---
Tradus automat folosind DeepL API
Solution: Increase timeout in Lambda Configuration → General configuration → Timeout (set to 60-90 seconds)
Solution: Add environment variable in Lambda Configuration → Environment variables
Solutions:
- Verify both sender and recipient emails in SES
- Check SES is out of sandbox mode (or both emails are verified)
- Check CloudWatch Logs for errors:
aws logs tail /aws/lambda/newsletter-translator --follow
Solution: The email might be:
- Too short (< 50 characters after cleaning)
- Heavily image-based
- Not properly formatted HTML
Try forwarding the raw email or check Lambda logs.
Solution: DeepL is excellent for Romanian, but if you need more control over technical terminology:
- Consider switching to GPT-4o-mini (see
RESEARCH.mdfor alternative implementation) - Can provide custom glossaries with DeepL Pro plan
Using AWS Console:
- Go to Lambda → Functions →
newsletter-translator - Click Monitor tab → View logs in CloudWatch
Using AWS CLI:
# Tail live logs
aws logs tail /aws/lambda/newsletter-translator --follow
# Get recent logs
aws logs tail /aws/lambda/newsletter-translator --since 1h- Go to DeepL Account
- View Characters translated this month
- Free tier limit: 500,000 characters/month
aws ses get-send-statisticsCreate labels for different newsletter types:
AI/Newsletters/Translated
AI/Newsletters/Original
Set up filters to auto-label translated emails:
- From: [email protected]
- Subject:
[RO] - Apply label: AI/Newsletters/Translated
-
DeepL Free Tier: 500,000 chars/month
- Average newsletter: ~5,000 words = ~6,500 characters
- Can process ~77 newsletters/month free
-
If exceeding free tier:
- Consider GPT-4o-mini (~$0.75 per 1M characters)
- See
RESEARCH.mdfor implementation
Update Gmail filter to include all sources:
From: ([email protected] OR [email protected] OR [email protected])
The current implementation extracts text only. To preserve HTML formatting:
- Modify
lambda_function.pyto pass HTML directly to DeepL - DeepL API supports HTML translation with
tag_handling: "html" - Update email sending to use HTML MIME type
If you receive many newsletters:
- Add SQS queue between API Gateway and Lambda
- Process in batches to optimize API calls
- Reduces costs and improves reliability
When you make changes to lambda_function.py:
# Rebuild deployment package
./deploy.sh
# Update Lambda function
aws lambda update-function-code \
--function-name newsletter-translator \
--zip-file fileb://newsletter-translator-lambda.zipOr via AWS Console:
- Go to Lambda → Functions →
newsletter-translator - Code tab → Upload from → .zip file
- Upload
newsletter-translator-lambda.zip
-
Never commit API keys to version control
- Use
.envfor local development - Use Lambda environment variables for production
- Use
-
Restrict API Gateway access (optional):
- Add API key requirement
- Use AWS WAF to block unauthorized IPs
- Enable CloudWatch Logs for monitoring
-
Use IAM least privilege:
- Lambda execution role should only have:
- CloudWatch Logs write access
- SES send email access
- Lambda execution role should only have:
-
Rotate API keys periodically:
- DeepL API keys
- AWS access keys (if using CLI)
Feel free to submit issues or pull requests for improvements!
MIT License - feel free to use and modify for your needs.
✅ The project is complete when:
- You can forward an English AI newsletter to the webhook email
- The system processes it automatically (no manual intervention)
- A readable Romanian translation appears in your inbox within 1-2 minutes
Enjoy your automated newsletter translations! 🚀