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
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