Members-only tutorial
Watch the video and get the practice sheet with membership.
About this Tutorial
Sheet Resources
Video Transcript
<div>0:00 You're going to learn in this video how to send two emails in the same trigger Learn how to set up triggers to automate tasks in your Google Sheets. Opens in new tab . This is a fairly simple concept, doesn't take much time to go through it, but I want to create a situation in which, ah, you would, maybe, have to send two emails to two different people, and maybe on a weekly basis, on a<br>0:16 weekly trigger Learn how to set up triggers to automate tasks in your Google Sheets. Opens in new tab .
We're going to set up the Apps Script Discover the basics of Google Apps Script for enhancing your Sheets. Opens in new tab , um, and I want to stress to you that this is a fairly simple idea, but it is not intuitive.<br>0:28 Ah, if you are a beginner at Apps Script Discover the basics of Google Apps Script for enhancing your Sheets. Opens in new tab , or even just trying to do Apps Script Discover the basics of Google Apps Script for enhancing your Sheets. Opens in new tab the very first time, ah, or even if you've been doing Apps Script Discover the basics of Google Apps Script for enhancing your Sheets. Opens in new tab for a while and copying and pasting, ah, Apps Scripts into your Apps Script Discover the basics of Google Apps Script for enhancing your Sheets. Opens in new tab , the code into your Apps Script Discover the basics of Google Apps Script for enhancing your Sheets. Opens in new tab , this may not be a very simple concept to you, <br>0:46 or you may not understand that it could occur, that you could do this.
We're just going to basically line up the two emails, one first, and then under it, the second one.<br>0:56 And I'll go through a few of the issues that you may run into because. I just ran into this with a client.<br>1:03 They asked, is this even possible? I was like, I didn't know, you didn't know this was possible. And it was, ah, done within minutes, not hours.<br>1:12 So we're going to go up to Extensions, Apps Script Discover the basics of Google Apps Script for enhancing your Sheets. Opens in new tab and create an Apps Script Discover the basics of Google Apps Script for enhancing your Sheets. Opens in new tab here. We want to send two emails of different data Understand how to manage and manipulate data in Google Sheets. Opens in new tab .<br>1:20 We have, say, a total sales and a monthly sales.
And we're sending this every single Friday, just an update to two different people.<br>1:29 So let's create a name for this, sales updates. We're going to create a function Get to know how functions work in Google Sheets and Apps Script. Opens in new tab that will be triggered as a timed trigger Learn how to set up triggers to automate tasks in your Google Sheets. Opens in new tab .<br>1:38 So we're going to say send email. We could say send emails here, or just send email. Maybe you only set up one, and now you want to create another one.<br>1:46 Ah, and then we will get the data Understand how to manage and manipulate data in Google Sheets. Opens in new tab , which will be variable data Understand how to manage and manipulate data in Google Sheets. Opens in new tab to send equals spreadsheet Explore the features and functionalities of Google Sheets. Opens in new tab app dot get Spreadsheet Explore the features and functionalities of Google Sheets. Opens in new tab .<br>2:00 Get sheet by name, and in one case we want to get the total. Get range Learn about selecting and working with ranges in Google Sheets. Opens in new tab .
We want, here, A1 to B6.<br>2:17 A1 to B6. Get values Understand how to retrieve and use values from your Google Sheets. Opens in new tab . And we want to send that as a body of a text, ah, as an email, uh, text.<br>2:27 So we will start gmail app dot get actually. Send email. Here we just need three things. We need the recipient, who it's to.<br>2:36 So in my case, I'm going to send it to myself, actually. Owner Find out how to identify the owner of a Google Sheet. Opens in new tab , variable owner Find out how to identify the owner of a Google Sheet. Opens in new tab equals. Get active spreadsheet Learn how to reference the currently active spreadsheet in Apps Script. Opens in new tab . Get owner Find out how to identify the owner of a Google Sheet. Opens in new tab .
Get email.<br>2:52 So if you want to put your email in here, you just have to change this to text or whoever you're sending it to and we'll do this, the subject will be, uh, total updates, total sales updates.<br>3:09 What I'm going to do at the end of this is add a timestamp Discover how to add timestamps to your data in Google Sheets. Opens in new tab plus new date. And then we need the body.<br>3:20 This is the body or the text of the email. Now we could potentially just send data Understand how to manage and manipulate data in Google Sheets. Opens in new tab to send And let's see what that looks like, because that might not be very nice.<br>3:34 Let's make sure it saves. We are going to click run.
We'll have to authorize it the very first time we run it before we create that trigger Learn how to set up triggers to automate tasks in your Google Sheets. Opens in new tab .<br>3:46 As we can see, very simply, it doesn't look very nice, so I'm going to actually create a little bit of HTML here.<br>3:53 So instead of HTML, I actually just created a plain text Understand the difference between plain text and formatted text in emails. Opens in new tab with this slash n for new lines and instead of a data Understand how to manage and manipulate data in Google Sheets. Opens in new tab to send, we're going to do this.<br>4:01 The text body. So let's see what that looks like. And that's a pretty fairly simple text email. Here, uh, we have this.<br>4:12 Uh, we will now send a second email. So this is sending one email to one person.
It's this Gmail app here, dot send email, that will actually send the email.<br>4:26 So what you might think, if we create this as a trigger Learn how to set up triggers to automate tasks in your Google Sheets. Opens in new tab , let's, uh, go and do that, send email. Triggers.<br>4:34 Let's move my face over here, add trigger Learn how to set up triggers to automate tasks in your Google Sheets. Opens in new tab , choose which function Get to know how functions work in Google Sheets and Apps Script. Opens in new tab , send email. Event source will be time driven. We will send this every week, every Friday at 5pm.<br>4:48 There we go. And I will click save. So once you've created that trigger Learn how to set up triggers to automate tasks in your Google Sheets. Opens in new tab , you think, you may think, that I need to create a whole nother function Get to know how functions work in Google Sheets and Apps Script. Opens in new tab , and create a whole nother trigger Learn how to set up triggers to automate tasks in your Google Sheets. Opens in new tab .<br>5:00 In order to do this.
But what we can do with our program is we are already sending this. All we need to do is send another email in here.<br>5:10 So inside of this function Get to know how functions work in Google Sheets and Apps Script. Opens in new tab , we're just going to copy this send email and we'll redo Learn how to redo actions in Google Sheets effectively. Opens in new tab everything.
So instead of total sales, we'll call this monthly sales update.<br>5:22 And instead of text body, what I want to do is copy all of this and put it just between here.<br>5:31 In our case, we are going to be sending it to the same person ourselves just for, uh, to see it, but you can always send it to a different person here.<br>5:41 But this data Understand how to manage and manipulate data in Google Sheets. Opens in new tab to send will be called monthly. This is what I like to do. I like to create new variables that have a different text in them.<br>5:51 And we're going to call this monthly.
And this has exactly, by the way, the same numbers here, or not numbers, but the same area. We're going to, we just have these formulas that are looking at whatever today's date is, putting the text of the month there, this month, and then counting whatever this <br>6:11 month's counts are up to date. These are actually fun, pretty, pretty fun formulas. Alright, so we have the same area and we want to rename this.<br>6:25 To rename this very easily, I will use command D to select all Find out how to select all data in your Google Sheets quickly. Opens in new tab of those text bodies.
And make sure I'm at the end of each one and call this monthly.<br>6:38 Data Understand how to manage and manipulate data in Google Sheets. Opens in new tab to send monthly will be updated here as well. There, so we've updated our variables so that our variables above this for this total email are one.<br>6:51 And then we have different variables for the monthly. And that's how we can create these two emails and send two emails in one function Get to know how functions work in Google Sheets and Apps Script. Opens in new tab and only use one trigger Learn how to set up triggers to automate tasks in your Google Sheets. Opens in new tab .<br>7:06 So let's see. Now I will, uh, hit run again to test this out. And now we have two different emails.<br>7:15 We have total sales emails and monthly sales updates. We do need to update the text here.
This should be monthly.<br>7:25 It's always good to check. And there we go. So, that's how you can create two emails or send two emails with one function Get to know how functions work in Google Sheets and Apps Script. Opens in new tab , in one trigger Learn how to set up triggers to automate tasks in your Google Sheets. Opens in new tab , without having to create another trigger Learn how to set up triggers to automate tasks in your Google Sheets. Opens in new tab , without having to create a whole nother function Get to know how functions work in Google Sheets and Apps Script. Opens in new tab .<br>7:38 We can run this function Get to know how functions work in Google Sheets and Apps Script. Opens in new tab , send email, with those two emails.
Again, this is not very intuitive if you are a beginner at Apps Script Discover the basics of Google Apps Script for enhancing your Sheets. Opens in new tab , but I wanted to share Explore how to share your Google Sheets with others. Opens in new tab this with you, at least this fairly simple concept, uh, because it did come up actually recently and thought it would be very helpful for you.<br>7:58 If you If are watching this on bettersheets.co, you can get this. Spreadsheet Explore the features and functionalities of Google Sheets. Opens in new tab down below.
If you're watching this somewhere else, become a member of bettersheets.co to get that spreadsheet Explore the features and functionalities of Google Sheets. Opens in new tab .<br>8:07 You can get the sheet, and you can get the Apps Script Discover the basics of Google Apps Script for enhancing your Sheets. Opens in new tab as well, because there's some actually pretty funny, funky, interesting formulas here if you're looking for, like, to see what text, uh, is to date this month's, uh, this month's name in text instead of a number Understand how to work with numbers in Google Sheets. Opens in new tab , we can use this formula Get familiar with the syntax used in Google Sheets formulas. Opens in new tab here.<br>8:25 I thought that'd be interesting for you. Watch other videos here on bettersheets.co or on youtube.com slash better sheets.</div>