The Digital Messenger
Turn your script into a mailman that never stops working.
We’ve been working inside sheets, but now we’re heading to the Inbox. Today, you will learn the command that lets Google send real emails to real people using your code.
- How to use the
MailAppcommand. - The three "Ingredients" of an email (Who, What, and the Message).
- How to send a test email to yourself.
This is for the "Communicator." If you want to send automatic certificates, birthday wishes, or even just a daily reminder to do your homework, this is the magic tool you need.
Think of a Carrier Pigeon.
You write a note, give the pigeon an address, and let it go. You don't have to walk to your friend's house yourself.
MailApp is that pigeon. Once you give it the info, it flies across the internet and drops the message exactly where you told it to.
To send an email, the computer needs to know three things:
- Recipient: Whose email address is this going to?
- Subject: What is the "Title" of the email?
- Body: What is the actual message?
In Apps Script, we use a command called MailApp.sendEmail() and we put these three things inside the parentheses.
Let's look at the basic structure. We put the email address, then the subject, then the body—all separated by commas.
// Send a simple email
MailApp.sendEmail("yourname@gmail.com", "Test", "It works!");
}
Replace WRITE_YOUR_EMAIL_HERE with your actual Gmail address to test it!
When you run this for the first time, Google will ask for permission again. This is because sending emails is a "Big Deal."
Follow the same steps as before: Advanced > Go to Project (unsafe) > Allow. Once you do, check your Gmail. You’ll have a new message from yourself!
Click to troubleshoot your email script
1. Typos: Is there an extra space in the email address? " name@gmail.com" will fail. It must be "name@gmail.com".
2. The Commas: Make sure you have commas between the three parts: (who, subject, body). If you forget one, the robot gets confused.
3. Spam Folder: Sometimes, because it's a test script, your email might hide in the "Spam" or "Promotions" folder. Go hunt for it!
Can you change the body variable to your favorite joke? Run the script and send the joke to your own inbox. Did it make you laugh?
Gaming Apps use this! When you forget your password and click "Reset," a script just like this finds your email and sends you a link automatically. No human at the gaming company is typing that email—a robot is!
You’ve given your robot a voice! You can now send information out of the spreadsheet and into the real world. This is a huge milestone on your journey to becoming an App Builder.
Status: Digital Mailman 📧 | Level: Inbox Influencer ✉️