Skip to content

WebNinjaDeveloper.com

Programming Tutorials




Menu
  • Home
  • Youtube Channel
  • Official Blog
  • Nearby Places Finder
  • Direction Route Finder
  • Distance & Time Calculator
Menu

Google Apps Script Gmail API Example to Send Multiple Email Using MailApp & GmailApp Library in Javascript

Posted on November 26, 2022

 

 

Welcome folks today in this blog post we will be sending multiple email using mailapp and gmailapp library in google apps script and javascript. All the full source code of the application is shown below.

 

 

Get Started

 

 

In order to get started you need to create a new google apps script project and make a code.gs file and copy paste the below code

 

 

Using MailApp Library

 

 

First of all we will be using the MailApp library send() method to actually send the message to the target email address and also we can have additional fields such as cc,Bc & Reply to etc.

 

 

1
2
3
4
5
6
7
8
9
10
11
12
function sendEmailMessage() {
  var message = {
    to: "harshadchopra1997@gmail.com",
    subject: "Check out Apps Script",
    body: "I just discovered Apps Script and it's so cool!",
    cc: "cc@example.com",
    bcc: "bcc@example.com",
    replyTo: "help@example.com",
    name: "Spreadsheet Dev"
  }
  MailApp.sendEmail(message);
}

 

 

As you can see in the above code we are using the sendEmail() method inside the MailApp library and here in the argument we are passing the configuration object which contains all the properties of the mail such as the email address to which you need to send. And then we have the subject of the mail and then we have the body of the email.

 

 

Now you need to run this function at the very top as shown below

 

 

 

 

 

 

 

 

 

As you can see that the email has been successfully sent to the specified email address with the subject and the body. And it is also succesfully received.

 

 

Using GmailApp Library

 

 

You can do the same task by using the GmailApp Library. The code will look like this as shown below

 

 

JavaScript
1
2
3
4
5
function sendEmailMessage() {
  GmailApp.sendEmail("harshadchopra1997@gmail.com,sharmagautam1997dob@gmail.com", "test message", '' , {
    htmlBody: "test message",
    from: "geekygautam1997@gmail.com"});
}

 

 

As you can see here we are sending emails to multiple people at once by inserting a comma and then we are providing the subject and the actual htmlBody of the message. Now for this guys we need to grant the permission of the gmail account as shown below

 

 

 

Recent Posts

  • Android Java Project to Download Multiple Images From URL With Progressbar & Save it inside Gallery
  • Android Java Project to Capture Image From Camera & Save it inside Gallery
  • Android Java Project to Crop,Scale & Rotate Images Selected From Gallery and Save it inside SD Card
  • Android Kotlin Project to Load Image From URL into ImageView Widget
  • Android Java Project to Make HTTP Call to JSONPlaceholder API and Display Data in RecyclerView Using GSON & Volley Library
  • Angular
  • Bunjs
  • C#
  • Deno
  • django
  • Electronjs
  • java
  • javascript
  • Koajs
  • kotlin
  • Laravel
  • meteorjs
  • Nestjs
  • Nextjs
  • Nodejs
  • PHP
  • Python
  • React
  • ReactNative
  • Svelte
  • Tutorials
  • Vuejs




©2023 WebNinjaDeveloper.com | Design: Newspaperly WordPress Theme