How to Send Bulk Emails from Google Sheets with Apps Script
Learn how to send bulk emails directly from Google Sheets using Apps Script in this informative tutorial. This video guides you through the process of coding a function to automate email sending to a list of recipients.
In this video, I'm going to show you how to send bulk emails. We have a list of emails here, and we want to send them an email, each one of them a email that says, Hey, how are you doing? So we're going to go up to extensions app script . Just to know we are looking at the emails in D two to D 11. That's range is gonna be important as we code this up. We're gonna use app script . We're gonna write function , send emails, and we're going to do something called spreadsheet app. Do get active spreadsheet sheet by name. We're going to get sheet one in this case. Sheet one. We wanna get range . They said we want to get D two colon. getValues . Now, this will be an array. We can actually look at this array, logger. log. We're going to call this variable emails equals. We're going to look at that and see what happens. What it looks like, we'll save it.
We'll run it. So this looks like the actual values , but it is an array of arrays . So let's say we want to get the very first item. We're going to do emails zero. And let's see what that looks like. And we can also do another zero and we're going to get the value within that array. Click run again and see we get the actual email. Now, if we do one in brackets to begin with, let's save it and run it. We're gonna get Isabella, which is our second item. So what we need to do is iterate this number one or 0 0 1, 2 3. We need to iterate through it and send them an email. So we'll do Gmail app dot send email. We're gonna need a recipient. We're going to need a subject and the body of the email. So the recipient, we will use a variable called rec, or recipient, sub for subject, and body for body.
So let's create those variables. Variable sub equals how are you doing? And variable body equals how Just text, Hey, how are you today? Now our recipient is going to need to be a for loop. So we're going to call for i equals zero. We're going to start at zero and we're going to do it as however long the length of emails is. So emails dot length. And we're going to iterate plus one each time, so we're going to use plus plus there. Now inside of this curly brackets, we need to put all of these here. We need to put this gmail app and these variables. Before we go on, let's check this for loop is actually looping. So instead of a one, I'm going to put an i. Because this is the, I is the iterator, I'm going to save this and run it.
and we can see the list of every single email that we have. So we know that this emails, I, zero with these square brackets is going to be our recipient. So we're going to do variable recipient equals emails, I in square brackets, and then zero to get the actual value. And. Once we uncomment this, we will now send an email. I'm not going to send an email because these are all fake emails. But it's going to be a very plain text email called how are you doing with the subject body. I can actually send this to myself and you'll see. This is the email that I sent to myself and iterated through it. It's going to me. It's saying, hey, how are you doing? Here is the subject. How are you doing? Very plain text email. And that's how you send bulk emails. I'll put this sheet down below , in the description. If you are a better sheets member, you can get way more automations over at better sheets.
co. If you're not a member yet, consider becoming a member today for a very small monthly subscription price.