- How can you automate a personalized email campaign with LLM on a VPS?
- Overall Architecture — Personalized Email Campaign Generation Automation with LLM Running on VPS
- Prerequisites and server selection
- Practical Implementation — Step by Step
- Email settings and deliverability
- Security and privacy
- Monitoring, Bounce Handling, and Metrics
- Scalability and model optimization
- Compare locations and recommend campaigns
- Implementation checklist (step by step)
- Practical tips for different teams
- Conclusion
- Frequently Asked Questions
How can you automate a personalized email campaign with LLM on a VPS?
This technical, step-by-step guide shows how to deploy an LLM on a VPS or cloud server, generate personalized email texts, and run sending campaigns at scale securely and reliably by properly configuring the MTA and DNS records.
Overall Architecture — Personalized Email Campaign Generation Automation with LLM Running on VPS
The typical architecture includes the following components, each of which has a specific role in generating, queuing, and sending emails:
- LLM inference server (on VPS/GPU Cloud) — Implementing the model to produce personalized content.
- Application API (FastAPI/Flask) — Interface between the data bank, LLM and the send queue.
- Message queue and worker (Redis + Celery or RabbitMQ) — Background sending and pricing management.
- MTA or SMTP relay (Postfix/Haraka or external service like Mailgun/Sendgrid) — Actual email sending.
- Monitoring & Logging (Prometheus + Grafana + ELK) and bounce management.
- DNS records: SPF, DKIM, DMARC and PTR for dedicated IP.
Advantages of deploying on a VPS or cloud server:
- Full control over data and model — Important for privacy and compliance.
- Ability to use GPU Cloud For inferencing large models.
- IP allocation and warm-up management To improve deliverability.
- Geographic distribution Using 85+ locations to reduce latency.
Prerequisites and server selection
Hardware and location selection
For large models (7B/13B+) It is recommended to use a server GPU with 16–48 GB VRAM (e.g. A100/RTX 3090/4090). For smaller or quantized models such as LLama-2-7B q4_0 You can use a CPU with 32+ GB of RAM.
Location: To increase delivery in the local inbox, IP from the same geographic region can help; but for overall deliverability, IP block and its history are more important.
Software
Suggested software elements:
- Docker, Docker Compose or Kubernetes (for scale).
- text-generation-inference (TGI) or vLLM for inference; lighter paths like GGML/llama.cpp for CPU servers.
- FastAPI for API, Celery + Redis for queue, Postfix/Haraka or SMTP relay for sending.
Practical Implementation — Step by Step
Basic installation (Ubuntu example)
Instructions for installing Docker on Ubuntu:
sudo apt update
sudo apt install -y docker.io docker-compose
sudo systemctl enable --now dockerDocker Compose example for LLM + API + Redis
A simple version that runs TGI as inference and a FastAPI app:
version: "3.8"
services:
tgi:
image: ghcr.io/oobabooga/text-generation-inference:latest
ports:
- "8080:8080"
volumes:
- ./models:/models
environment:
- MODEL_ID=/models/your-model
deploy:
resources:
reservations:
devices:
- capabilities: [gpu]
api:
image: yourrepo/email-llm-api:latest
build: ./api
ports:
- "8000:8000"
environment:
- TGI_URL=http://tgi:8080
- REDIS_URL=redis://redis:6379
depends_on:
- tgi
- redis
redis:
image: redis:6
ports:
- "6379:6379"Simple API Example (Python + FastAPI) — LLM Call and Formatting
Sample code snippet for generating content from TGI and queuing for sending in the background:
from fastapi import FastAPI, BackgroundTasks
import requests, smtplib
from jinja2 import Template
app = FastAPI()
def send_email(smtp_host, smtp_port, user, password, to, subject, body):
import smtplib
from email.mime.text import MIMEText
msg = MIMEText(body, "html")
msg["Subject"] = subject
msg["From"] = user
msg["To"] = to
with smtplib.SMTP(smtp_host, smtp_port) as s:
s.starttls()
s.login(user, password)
s.sendmail(user, [to], msg.as_string())
@app.post("/generate-and-send")
def generate_and_send(payload: dict, background_tasks: BackgroundTasks):
tgi_resp = requests.post("http://tgi:8080/generate", json={
"prompt": f"Create a personalized marketing email for {payload['name']} about {payload['product']}",
"max_new_tokens": 200
}).json()
email_body = tgi_resp["generated_text"]
template = Template(email_body)
final = template.render(**payload)
background_tasks.add_task(send_email, "smtp.local", 587, "[email protected]", "smtp-pass", payload["email"], "پیشنهاد ویژه", final)
return {"status": "queued"}Email settings and deliverability
SPF, DKIM, DMARC
Sample records and key steps:
- SPF: TXT record in DNS with sample value:
"v=spf1 ip4:YOUR.IP.ADD.RESS include:spf.yourrelay.com -all" - DKIM: Using OpenDKIM. Key generation:
opendkim-genkey -t -s mail -d example.com - DMARC: Sample record:
_dmarc.example.com TXT "v=DMARC1; p=quarantine; rua=mailto:[email protected]; ruf=mailto:[email protected]; pct=100"
PTR, dedicated IP and Warm-up
PTR (reverse DNS) It should return the email hostname.
Warm-up: Use a dedicated IP and warm-up program: initially send limited amounts (e.g. 50–200 emails per day) and gradually increase to avoid blocking.
Rate limiting and queuing
Sample Postfix configuration for rate and connection limiting:
smtpd_client_message_rate_limit = 100
smtpd_client_connection_count_limit = 10For large campaigns, it is usually better to use a trusted SMTP relay and have the app side only control the sending queue based on the provider's restrictions.
Security and privacy
TLS: Always send SMTP with STARTTLS or SMTPS. For Postfix in main.cf:
smtpd_tls_cert_file=/etc/letsencrypt/live/example.com/fullchain.pem
smtpd_tls_key_file=/etc/letsencrypt/live/example.com/privkey.pemKey and token storage: Use Vault or Secret Manager.
Sensitive data encryption: In PostgreSQL, you can use pgcrypto or field-level encryption.
Monitoring, Bounce Handling, and Metrics
Bounce handling: Receiving a bounce via VERP or a specific mailbox is necessary to process and update the status in the DB.
KPIs: delivery rate, open rate, click rate, bounce rate, spam complaints.
System monitoring: Prometheus for CPU/GPU/VRAM, Grafana dashboards for latency inference, queue length and success/fail metrics.
Scalability and model optimization
Using GPU Cloud and Quantization
For large models, GPU Cloud is recommended. Quantization (4-bit/8-bit) and the use of techniques such as vLLM or Triton can provide up to 4–10x memory reduction and throughput increase.
Caching products and prompt templates
To reduce the cost of each model call, cache parts of text that are repetitive and use prompt templates and secure methods to replace PII fields.
Compare locations and recommend campaigns
- Local audience: If most recipients are in the same country/continent, a VPS in the same region can reduce latency and sometimes increase interoperability.
- Delivery to major providers (Gmail, Yahoo): More important than location is IP block history and DNS settings.
- Protection from attacks: Using anti-DDoS servers and BGP networking is essential for service continuity during an attack.
Implementation checklist (step by step)
- Select location and server type (GPU vs CPU) based on model.
- Setting up a VPS and installing Docker/Docker Compose.
- Deploying the LLM inference server (TGI/vLLM) and API.
- Queue configuration (Redis + Celery) and workers.
- Set up a valid MTA or select a valid SMTP relay.
- Generate DKIM key and add SPF, DKIM, DMARC records.
- Setting up TLS with certbot and setting PTR.
- Perform IP warm-up as scheduled (7–14 days).
- Active monitoring and bounce processing.
- A/B testing and KPI measurement.
Practical tips for different teams
- For DevOps: Use IaC (Terraform or Ansible) for network and DNS deployment and use Container registry to store images.
- For marketing: Use delivery and engagement metrics to set prompts and segment targets.
- For security: Restrict access to the LLM API with IP allowlist and rate limits.
Conclusion
LLM on VPS personalized email campaign generation automation combines the power of language models, queue architecture, and email infrastructure. By choosing the right location from 85+ global locations, using GPU servers for inferencing, and fine-tuning SPF/DKIM/DMARC and security policies, campaigns can be run with higher open and conversion rates and lower risk.
If you need to check the detailed configuration (CPU/GPU, location, dedicated IP, and warm-up plan), you can take advantage of the professional hosting and configuration options available in the services or consult with the technical team.





