Dashboard Mode - Sending emails from Sheets
Goal
Send personalized emails automatically using data from Google Sheets to save time and avoid manual errors.
Send personalized emails automatically using data from Google Sheets to save time and avoid manual errors.
| Name | Order ID | Order Date | Status | |
|---|---|---|---|---|
| Alice | alice@example.com | 1001 | 2024-06-01 | Shipped |
| Bob | bob@example.com | 1002 | 2024-06-02 | Processing |
| Carol | carol@example.com | 1003 | 2024-06-03 | Delivered |
| David | david@example.com | 1004 | 2024-06-04 | Cancelled |
| Eve | eve@example.com | 1005 | 2024-06-05 | Shipped |
=COUNTA(A:A)-1 shows 5 orders.=COUNTIF(E:E, "Shipped") shows 2 shipped orders.MailApp.sendEmail().function sendOrderEmails() {
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
const data = sheet.getRange(2, 1, sheet.getLastRow() - 1, 5).getValues();
data.forEach(row => {
const [name, email, orderId, orderDate, status] = row;
if (email && status !== 'Cancelled') {
const subject = `Order Update for Order #${orderId}`;
const body = `Hi ${name},\n\nYour order placed on ${orderDate} is currently: ${status}.\nThank you for shopping with us!`;
MailApp.sendEmail(email, subject, body);
}
});
}+----------------------+---------------------+ | Total Orders (5) | Orders Shipped (2) | +----------------------+---------------------+ | Send Emails Button | +-------------------------------------------------------------+
Clicking the "Send Emails" button runs the script that reads the current sheet data and sends emails only to customers whose status is not "Cancelled". If you update the data (add/remove orders or change status), the KPIs update automatically and the script sends emails based on the latest data.
If you add a filter to show only orders with status "Shipped", which components update?