Academy ↓
Hey there stranger!
Sign up to get access.
Spreadsheet Automation 101 Lesson 3: Email Other People For Loop
About this Tutorial
Video Transcript
0:09 Well, what if we have multiple people we wanna send emails to? So I created another tab called emails and I have a list of email addresses.
0:17 This is all the same, my own email address, just with some dots in it. Now how do we send the same email to all those different people?
0:25 Well, we use the same four loop, a similar thing with the four loop. So just to re re review, we are sending the recipient only one time here to one email address as text.
0:37 We'll change that. We're sending them the subject tasks not done, and then we're sending them the array of not done tasks.
0:46 We're using this four loop here to figure out which ones we're sending and then we're using this line of code that the whole thing hinges on this one line of code, which is send to a recipient, the subject and the body, which is not done tasks.
1:01 Okay? So what we need to do is actually put this mail app, the whole reason we have everything above it into a for loop and get the array of all of the emails that we got.
1:14 So same thing we do here. We're going to do variable. Let's do this, let's bring this up. We're gonna do variable emails equals or is spreadsheet app.
1:28 We wanna do the e sheet name is emails, I do believe emails a, let's just do exactly what we have a one to a four, A one, A four before we do anything else, right?
1:45 We can log this logger dot log email list. Let's see what that is. Let's comment out the mail app. So we're not sending emails, but we'll just see what that email list looks like.
1:59 We'll run email. Not done. Here we go. So we got an array of arrays. So all we need to do is get first array part, right?
2:08 We can also log those. Let's just log it just to be sure we got it correct. We'll do email list with bracket notation as we learned before.
2:16 We'll do zero. We'll also do just one. We'll just copy paste this just to double check that we're getting the right thing.
2:24 We got the right brackets in the right place. We'll do run. And there we go. We got Andre. Different email addresses.
2:33 Perfect. So now let's get this into the four loop. Okay, four I equals zero I is less than email list.email list dot length.
2:52 We'll do another semicolon and I plus plus. We'll put in brackets. Let's put that bracket up there. We want to send this email and we have variable recipient.
3:08 Maybe we'll write email here. Email, we'll change. Maybe we'll change that. Variable r e c. Just make sure that it is changed to email.
3:20 Well, what is that variable? It's email equals email list with BRCA notation. I, okay, so ideally, right we are moving all this just a little bit in, tab it in a little bit so it's easier to read.
3:37 We can log the whole list. We can get rid of that log, save it. We're getting all of the emails.
3:43 And then we're gonna send an email to each one. And that should end up in our sent. So let's say run.
3:49 See if we get any errors. Parameters, number string string. Don't match the method. Signature sent. Email line 20. What does that mean?
4:03 The parameters number String. String. Oh, might be because we need to add a zero. If it looked like those things we logged were actually still arrays and not a string.
4:16 So let's see if we just add this BRCA notation zero at the end. So it's the first item, which is an array.
4:23 It might only be one item array. We might need to get that one item there. So let's see if that fixes it.
4:29 Perfect Execution completed there and they do exist all in our sent folder. Perfect. So we've sent emails now to a bunch of people.
4:41 Well, it's all us. We sent those emails to ourselves. But this is a great way. So you can create a list of emails.
4:49 You wanna send maybe a report to every month or every week or every day. I don't know how many people you have to report to.
4:56 There are some additional things you can do here that I won't go into this video and won't be in this course, but you can add CC bcc.
5:05 You can do some pretty cool things with this mail app and email system. So I hope you can email lots of people the reports that you have to email them anyways, get a lot of stuff done.
5:15 Things are watching.
Courses
Spreadsheet Automation 101: Introduction to Pre-course Videos
Breaking Through Errors In Apps Script
Think Like a Programmer: Develop The Mindset of an Apps Script Coder
Tips to Navigating Thousands of Lines of Code In Apps Script
Spreadsheet Automation 101: Functions
Spreadsheet Automation 101: Variables
Spreadsheet Automation 101: Dot Notation
Spreadsheet Automation 101: Camel Case
Spreadsheet Automation 101: Parentheses
Spreadsheet Automation 101 Lesson 1: GetValue - Introduction to SpreadsheetApp
Spreadsheet Automation 101 Lesson 1: Spreadsheet Taxonomy
Spreadsheet Automation 101 Lesson 1: A1 Notation vs Row,Column Syntax
Spreadsheet Automation 101 Lesson 1: getActiveSpreadsheet() vs getActiveSheet()
Spreadsheet Automation 101 Lesson 1: onOpen() Trigger - Custom Menu
This Seems Like Automation
Spreadsheet Automation 101 Lesson 2: Get Values - Introduction
Spreadsheet Automation 101 Lesson 2: Arrays
Spreadsheet Automation 101 Lesson 2: For Loop
Spreadsheet Automation 101 Lesson 2: Bracket Notation
Spreadsheet Automation 101 Lesson 2: Logger.log()
Spreadsheet Automation 101 Lesson 2: If ( ){ } and Checkboxes
Spreadsheet Automation 101 Lesson 2: onEdit() Trigger
Introduction to Spreadsheet Automation 101 Lesson 3
Spreadsheet Automation 101 Lesson 3: MailApp
Spreadsheet Automation 101 Lesson 3: Email Yourself For Loop
Spreadsheet Automation 101 Lesson 3: Send Email Every Week Trigger
Spreadsheet Automation 101 Lesson 3: Email Other People For Loop
Spreadsheet Automation 101 Lesson 4: Access APIs Introduction
Spreadsheet Automation 101 Lesson 4: UrlFetchApp
Spreadsheet Automation 101 Lesson 4: OmdbAPI get ApiKey, get Data in URL
Spreadsheet Automation 101 Lesson 4: OmdbAPI get data in Apps Script
Spreadsheet Automation 101 Lesson 4: JSON (beautifier) and OmdbAPI parameters
Spreadsheet Automation 101 Lesson 4: OmdbAPI Parameter Picker
Automatically Clear Content | Refresh Reuse Recycle Templates
Automate Google Sheets With Zero Experience
Automatically Uncheck A Daily Checklist
Activate A Certain Sheet When Opening a Spreadsheet
Scoping Functions in Apps Script