Cloudflare Email Routing: tạo alias email theo domain miễn phí, không cần server email
Bạn có domain `yourcompany.com` và muốn dùng email `hello@yourcompany.com`, `support@yourcompany.com` mà không muốn trả $6/tháng/user cho Google Workspace? Cloudflare Email Routing cho phép tạo unlimited email alias chuyển tiếp về Gmail/Outlook cá nhân - hoàn toàn miễn phí. Với Email Workers, bạn còn có thể xử lý email bằng code: auto-reply, parse, lưu vào database. ---
Vấn đề
Mọi startup, freelancer, hay side project đều cần email professional theo domain riêng. Nhưng hosting email đầy đủ (Google Workspace, Zoho, Fastmail) thường:
- Tốn $3–12/user/tháng
- Cần cấu hình MX, SPF, DKIM, DMARC phức tạp
- Overkill nếu chỉ cần nhận email - không cần send từ domain
Cloudflare Email Routing giải quyết use case phổ biến nhất: nhận email @domain.com, chuyển về inbox đang dùng. Miễn phí, setup trong 5 phút.
Giải thích: Email Routing hoạt động thế nào
Sender → hello@yourcompany.com
→ Cloudflare MX servers
→ Email Routing rules
→ Forward → your.gmail@gmail.com
Cloudflare đứng làm MX server cho domain của bạn. Khi có email đến hello@yourcompany.com, Cloudflare forward nguyên vẹn về địa chỉ đích. Không lưu email, không đọc nội dung - chỉ route.
Giới hạn quan trọng: Email Routing là receive-only forwarding. Bạn không thể gửi email từ hello@yourcompany.com qua Cloudflare (cần SMTP để gửi - dùng Gmail "Send as" hoặc SMTP provider như Resend/Mailgun cho phần gửi).
Setup Email Routing
Bước 1: Bật Email Routing
Vào Cloudflare dashboard → chọn domain → Email → Email Routing → Get started.
Cloudflare sẽ tự động thêm các MX record cần thiết:
MX @ route1.mx.cloudflare.net (priority 26)
MX @ route2.mx.cloudflare.net (priority 16)
MX @ route3.mx.cloudflare.net (priority 61)
TXT @ "v=spf1 include:_spf.mx.cloudflare.net ~all"
Nếu domain đang có MX record của provider khác (Google, Zoho), Cloudflare sẽ cảnh báo conflict. Cần xóa MX record cũ trước.
Bước 2: Verify địa chỉ email đích
Trước khi tạo rule, phải verify email đích (Gmail, Outlook, etc.):
Email → Email Routing → Destination addresses → Add destination address
Nhập email personal của bạn → Cloudflare gửi verification email → click link xác nhận.
Bước 3: Tạo routing rule
Email → Email Routing → Routing Rules → Create address
Rule cơ bản - forward một địa chỉ:
| Field | Value |
|---|---|
| Custom address | hello (→ hello@yourcompany.com) |
| Action | Send to an email |
| Destination | your.gmail@gmail.com |
Tạo nhiều rule cho các địa chỉ khác nhau:
hello@yourcompany.com → personal@gmail.com
support@yourcompany.com → support-team@gmail.com
billing@yourcompany.com → finance@gmail.com
dev@yourcompany.com → dev-team@gmail.com
Không giới hạn số lượng rule - tất cả miễn phí.
Bước 4: Bật Catch-all (tùy chọn)
Catch-all nhận mọi email đến domain mà không có rule riêng:
Routing Rules → Catch-all address → Edit → Action: Send to email → [địa chỉ đích]
Hữu ích khi:
- Bạn cho địa chỉ email ngẫu nhiên khi đăng ký dịch vụ (
amazon-2026@yourcompany.com,netflix@yourcompany.com) → forward về inbox → biết site nào bị leak email - Nhận email không rõ nguồn gửi về domain để không bỏ sót
Gửi email từ alias (Gmail "Send as")
Email Routing chỉ nhận. Để gửi email từ hello@yourcompany.com qua Gmail:
Trong Gmail → Settings → See all settings → Accounts → Add another email address
Name: Your Name
Email address: hello@yourcompany.com
Treat as alias: ✓
SMTP Server: smtp.gmail.com
Port: 587
Username: your.gmail@gmail.com
Password: [App Password - bật 2FA trước]
Sau khi verify, trong Gmail bạn có thể chọn "From: hello@yourcompany.com" khi soạn email. Người nhận thấy đúng địa chỉ domain của bạn.
App Password: Vào Google Account → Security → 2-Step Verification → App passwords → tạo password riêng cho Gmail SMTP.
Email Workers: xử lý email bằng code
Email Workers là tính năng nâng cao - thay vì forward thẳng, email đi qua Worker để xử lý logic trước:
Routing Rules → Catch-all → Action: Send to a Worker
// email-handler.ts
import { EmailMessage } from "cloudflare:email";
import { createMimeMessage } from "mimetext";
export default {
async email(message: ForwardableEmailMessage, env: Env, ctx: ExecutionContext): Promise<void> {
// Đọc thông tin email
const from = message.from;
const to = message.to;
const subject = message.headers.get("subject") ?? "(no subject)";
// Lưu vào D1 database để tracking
await env.DB.prepare(
"INSERT INTO received_emails (from_addr, to_addr, subject, received_at) VALUES (?, ?, ?, ?)"
).bind(from, to, subject, new Date().toISOString()).run();
// Logic routing: tùy địa chỉ đích mà forward khác nhau
if (to.startsWith("support@")) {
// Forward đến team support + tạo ticket
await message.forward("support-team@gmail.com");
await createSupportTicket(env, { from, subject });
} else if (to.startsWith("billing@")) {
await message.forward("finance@gmail.com");
} else {
// Default: forward về inbox chính
await message.forward("main@gmail.com");
}
},
};
async function createSupportTicket(env: Env, data: { from: string; subject: string }) {
// Gọi webhook, tạo ticket trong hệ thống, gửi Slack notification...
await fetch(env.SLACK_WEBHOOK_URL, {
method: "POST",
body: JSON.stringify({
text: `📧 Support email từ ${data.from}: ${data.subject}`,
}),
});
}
Các use case với Email Workers:
- Auto-reply khi nhận email từ địa chỉ mới
- Parse email, lưu attachment vào R2
- Tạo support ticket tự động
- Webhook trigger khi nhận email từ sender cụ thể
- Spam filter tùy chỉnh trước khi forward
Cấu hình SPF, DKIM, DMARC
Cloudflare tự thêm SPF record khi bật Email Routing. Nhưng để email gửi đi từ Gmail "Send as" không bị spam, cần thêm DKIM và DMARC:
SPF (Cloudflare tự thêm):
TXT @ "v=spf1 include:_spf.mx.cloudflare.net include:_spf.google.com ~all"
Thêm include:_spf.google.com nếu dùng Gmail SMTP để gửi.
DMARC (thêm thủ công):
TXT _dmarc "v=DMARC1; p=quarantine; rua=mailto:dmarc@yourcompany.com; pct=100"
DKIM: Cấu hình trong Gmail Workspace hoặc SMTP provider bạn dùng để gửi - mỗi provider có hướng dẫn riêng.
Verify toàn bộ email config: dùng MXToolbox hoặc mail-tester.com.
So sánh các lựa chọn email theo domain
| Cloudflare Email Routing | Google Workspace | Zoho Mail Free | ImprovMX | |
|---|---|---|---|---|
| Giá | $0 | $6/user/tháng | $0 (5 user) | $0 (limited) |
| Nhận email | ✓ | ✓ | ✓ | ✓ |
| Gửi từ domain | Dùng Gmail SMTP | ✓ Native | ✓ | Dùng SMTP |
| Số alias | Unlimited | Unlimited | 5 | 2 (free) |
| Custom rules | ✓ Workers | ✓ | Cơ bản | Không |
| Catch-all | ✓ | ✓ | ✓ | ✓ |
| Email storage | Không (forward) | 30GB/user | 5GB/user | Không |
Khuyến nghị:
- Solo dev, side project: Cloudflare Email Routing + Gmail "Send as" → $0
- Team cần inbox riêng, calendar, Meet: Google Workspace
- Cần xử lý email bằng code: Cloudflare Email Workers
Best practices
1. Không dùng catch-all cho team lớn - mọi email không có rule sẽ vào một inbox, dễ bị bỏ sót. Tốt hơn là tạo rule explicit cho từng địa chỉ.
2. Dùng alias tracking khi đăng ký dịch vụ - github@domain.com, aws@domain.com - biết ngay dịch vụ nào bán/leak email của bạn.
3. Luôn verify SPF + DMARC trước khi bật - tránh email gửi đi bị mark spam.
4. Email Workers: dùng ctx.waitUntil() cho side effects (lưu DB, gọi webhook) để không delay forward:
ctx.waitUntil(saveToDatabase(env, emailData));
await message.forward("inbox@gmail.com"); // forward ngay, không chờ DB
5. Test với real email trước khi live - gửi email thử từ Gmail, kiểm tra header, xem có bị spam không.
Kết
Cloudflare Email Routing là giải pháp đẹp cho use case phổ biến nhất: email alias @domain.com, forward về inbox cá nhân, miễn phí hoàn toàn. Với Email Workers, nó mở rộng thành một email processing pipeline đầy đủ - auto-reply, ticket creation, webhook trigger - mà không cần server email.
Kết hợp với Workers và D1, bạn có thể xây dựng email-driven workflow hoàn chỉnh trên Cloudflare platform.
Tham khảo
- Cloudflare Email Routing - Official docs
- Email Routing setup
- Email Workers
- Postmaster / email deliverability
BKGlobal Tech Team