How to send email alerts from a Google Ads script
Sending notifications with MailApp, what to put in them, and the limits to keep in mind.
An alert that arrives in your inbox is the simplest useful output a script can have.
Sending a message
var ALERT_EMAIL = "you@example.com";
function main() {
var problems = findProblems();
if (problems.length === 0) return;
MailApp.sendEmail({
to: ALERT_EMAIL,
subject: "Budget alert: " + AdsApp.currentAccount().getName(),
body: problems.join("\n")
});
}Separate several recipients with commas. Use htmlBody instead of body for tables and links.
What makes an alert useful
- Say which account in the subject. At manager level every client produces its own message.
- Send only when there is something to act on. A daily "all fine" email trains people to ignore the sender.
- Include the numbers and a link so the reader can judge without opening Google Ads.
Things to know
- The email is sent from the user who authorized the script.
- Sending is subject to a daily quota per user. A script that emails once per keyword will exhaust it; collect findings and send one message.
- Emails are sent in preview. Check
AdsApp.getExecutionInfo().isPreview()if you want preview to stay quiet, or use your own address while testing. - The first use of
MailApprequires authorization.
Different recipients per client
Make the address a variable and set it per account in chiliad's Configure table, so the same script notifies the right account manager for each client.
Alerts about the script itself
An email from the script only arrives if the script runs. If it fails or stops, nothing is sent. Those cases are covered separately by chiliad's own alerts β see How to get alerts when a Google Ads script fails.