Google Apps Script Gmail API Example to Send Multiple Email Using MailApp & GmailApp Library in JS
Dec 9, 2025
Buy the full source code of application here:
https://procodestore.com/index.php/product/google-apps-script-gmail-api-example-to-send-multiple-email-using-mailapp-gmailapp-library-in-js-3/
Show More Show Less View Video Transcript
0:00
Uh hello friends, today in this tutorial
0:02
I will be showing you that how basically
0:04
you can use Google app script to send
0:06
out emails multiple emails to multiple
0:08
people. So first of all you need to go
0:11
to Google app script and we will be
0:13
building this application. So just go to
0:15
Google app script and click on start
0:18
scripting and you here you need to
0:19
create a new project here. Simply click
0:21
on this button new project and basically
0:24
guys you can follow the step-by-step
0:26
blog post and I have written a complete
0:28
blog post on my tutorial website ninja
0:30
developer.com. So the link will be there
0:32
inside the description of this video.
0:33
You you can just read the this
0:35
step-by-step blog instruction where I've
0:37
shown you all the screenshot that you
0:39
want to do. So it's better that you uh
0:42
read this blog post alongside with
0:44
watching this video. So just go to the
0:45
description of this video to get all the
0:47
source code. So now guys inside this uh
0:49
Google script file here you need to
0:51
write a new function here. We will write
0:53
this function as send mail and uh send
0:58
mail message. And basically we will be
1:01
executing this function. So the very
1:03
first thing guys we can use either two
1:05
approaches. We can use either the Gmail
1:07
app or we can use the mail app. These
1:10
are the two libraries that we can use
1:12
inside Google appcript to send out Gmail
1:16
messages and receive it. So first of all
1:19
I will show you the very basic approach.
1:21
We will construct a message object and
1:24
here guys you will be having the
1:26
different kinds of fields out there.
1:27
This is a two field. So this is the
1:29
email address to which you need to send
1:31
out the email. So I will write this
1:34
email.
1:37
So first of all I will show you how to
1:39
send out to a only one people which is a
1:42
single person. So put a comma and then
1:44
the subject of the message what is the
1:46
subject inside this object. So we will
1:49
simply say this is the
1:51
sample
1:54
Google appcript
1:56
message. So this will be the subject
1:58
guys. Put a comma and then we have the
2:01
body of the message. So basically in the
2:03
body this is the body of the message.
2:09
That's it. Put a comma and the next
2:11
field guys will be CC value. You can
2:15
just set this but these are not
2:17
necessary. And also we have a reply to
2:20
field also. So whenever you want to
2:22
reply to then you can simply say help at
2:25
the ratecodingsure.com.
2:28
So whenever you click the reply button,
2:31
this email address will automatically
2:32
gets inserted and here you can also
2:35
provide a name to your
2:37
let's suppose I provide my own name. So
2:40
this will be embedded inside the message
2:43
all these fields. That's all guys. After
2:46
that you can use this mail app library
2:50
guys. This is the actual library which
2:52
is used to send out messages and
2:54
basically it contains a method called as
2:57
send email.
3:00
You can even uh get the remaining daily
3:03
kota as well. So basically you get a
3:07
uh
3:09
you get as limited amount of daily kota
3:13
to send out messages. I think it's 200.
3:15
It is more than enough. So basically now
3:17
to save your project simply click on
3:19
save
3:21
and uh now we have this method here
3:24
which is send mail message. So this is a
3:26
run button guys. So if you click this
3:29
button your function will run. So now
3:32
basically we will select this method
3:35
which is send email and here we will
3:37
pass our object which is message. So
3:40
this will send out this email address to
3:42
this email address guys. So now if I
3:44
click run button. So first of for the
3:47
first time we need to first of all grant
3:49
the permission guys. So there will be a
3:51
popup window which will appear to you.
3:54
You need to grant the permission to send
3:56
out email addresses. So here you need to
3:58
it says that this project requires your
4:01
permission to access your data. So
4:03
simply click this option and uh simply
4:06
select your account
4:08
go to advance option and this one and
4:11
simply grant the permissions. So this
4:13
will allow the project to send email as
4:15
you. So basically it's not using the
4:18
Gmail API. It's just using this uh mail
4:21
mail app. So click on allow. And uh now
4:25
once it is executed you will see in the
4:27
console execution started and completed.
4:30
And now if I open my address here which
4:32
is this one. And you will see the email
4:35
message is received. You can see my name
4:38
is written here. This is the sample
4:40
Google appcript message. If I click this
4:42
is the body of the message. So we have
4:45
successfully sent out the email address
4:47
to this specified email. And if I click
4:50
reply here automatically you will see
4:52
this email that I mentioned here help at
4:54
the ratecodings.com is there. This is
4:57
coming because we have set all these
4:59
values here. You can customize these
5:01
values. Name reply to the body subject
5:04
of the email address two fields. You can
5:07
all customize inside your Google app
5:09
script. So this makes it very much easy
5:12
to send out messages. And the nice thing
5:14
about is that you can also use the
5:17
second parameter here. Let's suppose I
5:20
want to send out to multiple people. So
5:22
I can simply type here put a comma here
5:25
and then we can send out to multiple
5:27
people. So let me route write a second
5:30
one.
5:32
This is the second email address. So now
5:35
if I click the run button again guys so
5:37
you will see it will send out to two two
5:39
people at once. So now if I check my
5:44
this one
5:46
you can see this is a sample Google
5:48
appcript message. This is received here.
5:51
You can see that let me open this ID.
5:56
You can see that this is the sample
5:58
Google appcript message. So with this
6:02
application you can send out to multiple
6:04
email addresses at once. So if you're
6:07
looking for marketing or anybody you
6:10
need to send out email addresses to you
6:13
just need the email addresses simply use
6:15
the script and you can do that. And now
6:18
that I will show you the second approach
6:20
guys which uses the Gmail app and for
6:23
that you need to allow access to your
6:26
Gmail account. So that I prefer this
6:30
approach because uh it only requires a
6:32
single permission but you can even use
6:34
the second approach as well. Let me show
6:36
you. So in the second approach we have
6:39
the Gmail app and uh this contains a
6:42
method here which is called as send
6:43
email. The Gmail API contains a method
6:46
send email which allows you to send out
6:48
messages. So here basically you can send
6:52
out messages
6:55
like this. Let me again write
6:59
put a comma and then you just need to
7:02
write the email addresses to which you
7:04
need to send out. So these are the two
7:07
email addresses and now put a comma and
7:09
the second argument it takes guys is the
7:13
subject.
7:15
So let me
7:17
just write a subject
7:20
uh Gmail API message.
7:24
And then the third argument guys it
7:26
takes it's uh basically takes a object.
7:33
Third one is empty like this. And the
7:36
fourth one is an object. And inside this
7:38
object guys it takes uh various fields
7:42
out there which is the body of the
7:44
message. This is inside HTML body.
7:47
You can write anything here h1. This is
7:50
the heading. You can even just write
7:52
HTML tags as well. Put a comma and then
7:56
we have our from address. You can also
7:59
customize this also. Let's suppose I say
8:01
here admin at the rate.com.
8:04
So I will customize this from as well.
8:07
So this will the message will be coming
8:10
from this address. So you can even
8:13
customize this also. Now if I click run
8:15
here. So now you need to grant the
8:18
permission to use your Gmail account
8:20
guys. So again you need to review
8:21
permissions and you need to now select
8:24
your account. So this time you need to
8:26
allow the permissions from Gmail
8:29
account. So it can read compose send and
8:31
permanently delete all your G email from
8:33
Gmail. So this is slightly allowing more
8:37
permissions but uh I will prefer the
8:39
first approach which uses less
8:41
permissions. You will see execution
8:43
started completed. And now if I once
8:45
again check here you will see
8:52
if I now check here
9:02
sometimes it can take some time guys for
9:06
sending it.
9:12
>> [snorts]
9:12
>> Yeah, I think you can prefer the first
9:15
approach. This also works but it takes
9:17
some time because you are allowing the
9:20
Gmail API to send out email addresses.
9:23
So I think you can use the first
9:26
approach mail API it's better and it
9:29
also requires less permissions as well.
9:32
So it totally depends upon you which
9:34
approach you want to use. [gasps]
9:36
So thanks very much for watching this
9:38
video guys and uh go to the blog post to
9:40
get all the source code. Please hit that
9:42
like button, subscribe the channel and I
9:43
will be seeing you in the next
