Tự động hóa email marketing với Google Sheets và Apps Script
30 tháng 12, 2025
Cập nhật: 19 tháng 8, 2026
14 phút đọc
Bạn muốn gửi email hàng loạt mà không cần trả phí cho Mailchimp hay SendGrid? Google Sheets + Apps Script là giải pháp hoàn hảo!
Tổng quan hệ thống
Tính năng:
- ✅ Gửi email hàng loạt (tối đa 100 email/ngày với tài khoản miễn phí)
- ✅ Personalize email (Tên, công ty, sản phẩm...)
- ✅ Template HTML đẹp mắt
- ✅ Theo dõi trạng thái gửi
- ✅ Lên lịch gửi tự động
1. Thiết kế Google Sheet
Sheet "Contacts" - Danh sách liên hệ:
| Cột | Tên | Mô tả |
|---|---|---|
| A | Địa chỉ email | |
| B | Name | Tên người nhận |
| C | Company | Công ty |
| D | Status | Trạng thái: Active/Unsubscribed |
| E | LastSent | Ngày gửi email gần nhất |
| F | SendResult | Kết quả: Sent/Failed |
Sheet "Templates" - Mẫu email:
| Cột | Tên |
|---|---|
| A | TemplateName |
| B | Subject |
| C | HTMLBody |
2. Tạo Template Email HTML
<!DOCTYPE html>
<html>
<head>
<style>
.container { max-width: 600px; margin: 0 auto; font-family: Arial, sans-serif; }
.header { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 30px; text-align: center; }
.content { padding: 30px; background: #f8f9fa; }
.button { display: inline-block; padding: 12px 30px; background: #667eea; color: white; text-decoration: none; border-radius: 5px; }
.footer { text-align: center; padding: 20px; color: #666; font-size: 12px; }
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>🎉 Ưu đãi đặc biệt dành cho {{name}}!</h1>
</div>
<div class="content">
<p>Xin chào <strong>{{name}}</strong>,</p>
<p>Cảm ơn bạn đã quan tâm đến {{company}}!</p>
<p>Chúng tôi có ưu đãi đặc biệt dành riêng cho bạn:</p>
<ul>
<li>Giảm 30% tất cả sản phẩm</li>
<li>Miễn phí hỗ trợ cài đặt</li>
<li>Bảo hành 12 tháng</li>
</ul>
<p style="text-align: center; margin: 30px 0;">
<a href="https://sheet.com.vn/marketplace" class="button">Xem ngay →</a>
</p>
</div>
<div class="footer">
<p>© 2024 SheetStore. Bạn nhận email này vì đã đăng ký nhận tin.</p>
<p><a href="{{unsubscribe_link}}">Hủy đăng ký</a></p>
</div>
</div>
</body>
</html>
3. Code Apps Script
Script gửi email hàng loạt:
function sendBulkEmails() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const contactsSheet = ss.getSheetByName('Contacts');
const templatesSheet = ss.getSheetByName('Templates');
// Lấy template
const templateData = templatesSheet.getRange('A2:C2').getValues()[0];
const subject = templateData[1];
const htmlTemplate = templateData[2];
// Lấy danh sách contacts
const contacts = contactsSheet.getRange('A2:F' + contactsSheet.getLastRow()).getValues();
let sentCount = 0;
const maxDaily = 100; // Giới hạn Gmail miễn phí
contacts.forEach((contact, index) => {
const [email, name, company, status, lastSent, result] = contact;
// Chỉ gửi cho contacts active
if (status !== 'Active' || sentCount >= maxDaily) return;
// Personalize email
let personalizedBody = htmlTemplate
.replace(/{{name}}/g, name || 'Bạn')
.replace(/{{company}}/g, company || 'SheetStore')
.replace(/{{unsubscribe_link}}/g, 'https://yoursite.com/unsubscribe?email=' + email);
try {
GmailApp.sendEmail(email, subject, '', {
htmlBody: personalizedBody,
name: 'SheetStore Team'
});
// Cập nhật trạng thái
const row = index + 2;
contactsSheet.getRange(row, 5).setValue(new Date()); // LastSent
contactsSheet.getRange(row, 6).setValue('Sent'); // SendResult
sentCount++;
// Nghỉ 1 giây để tránh rate limit
Utilities.sleep(1000);
} catch (error) {
contactsSheet.getRange(index + 2, 6).setValue('Failed: ' + error.message);
}
});
Logger.log(`Đã gửi ${sentCount} email thành công!`);
// Gửi báo cáo cho admin
GmailApp.sendEmail(
'admin@yourcompany.com',
'Báo cáo gửi email ' + new Date().toLocaleDateString('vi-VN'),
`Đã gửi thành công ${sentCount} email.`
);
}
Lên lịch gửi tự động:
function createEmailSchedule() {
// Xóa trigger cũ
ScriptApp.getProjectTriggers().forEach(t => ScriptApp.deleteTrigger(t));
// Tạo trigger gửi mỗi ngày lúc 9h sáng
ScriptApp.newTrigger('sendBulkEmails')
.timeBased()
.everyDays(1)
.atHour(9)
.create();
}
4. Tạo Menu tùy chỉnh
function onOpen() {
const ui = SpreadsheetApp.getUi();
ui.createMenu('📧 Email Marketing')
.addItem('Gửi email ngay', 'sendBulkEmails')
.addItem('Lên lịch gửi hàng ngày', 'createEmailSchedule')
.addSeparator()
.addItem('Xem báo cáo', 'showReport')
.addToUi();
}
function showReport() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheetByName('Contacts');
const data = sheet.getRange('F2:F' + sheet.getLastRow()).getValues();
const sent = data.filter(r => r[0] === 'Sent').length;
const failed = data.filter(r => r[0] && r[0].startsWith('Failed')).length;
const total = data.filter(r => r[0] !== '').length;
const ui = SpreadsheetApp.getUi();
ui.alert(
'📊 Báo cáo Email Marketing',
`✅ Đã gửi: ${sent}
❌ Thất bại: ${failed}
📧 Tổng: ${total}`,
ui.ButtonSet.OK
);
}
5. Tips nâng cao
A/B Testing subject line:
function getSubjectLine(variant) {
const subjects = {
A: '🎉 Ưu đãi 30% - Chỉ hôm nay!',
B: 'Giảm giá đặc biệt dành cho bạn'
};
return subjects[variant];
}
Tracking mở email:
Thêm tracking pixel vào HTML:
<img src="https://yoursite.com/track?email={{email}}&campaign=jan2024" width="1" height="1" />
Lưu ý quan trọng
⚠️ Giới hạn Gmail:
- Tài khoản miễn phí: 100 email/ngày
- Google Workspace: 2000 email/ngày
⚠️ Tránh spam:
- Luôn có link hủy đăng ký
- Không gửi cho người chưa đồng ý
- Nội dung có giá trị
Kết luận
Với Google Sheets + Apps Script, bạn có thể xây dựng hệ thống email marketing miễn phí và mạnh mẽ. Hãy bắt đầu với số lượng nhỏ và mở rộng dần!
Xem thêm tại SheetStore
Chia sẻ bài viết:
Hoàng Mạnh Tuân
Bạn thấy bài viết hữu ích?
Đăng ký nhận thông báo khi có bài viết mới.
