DEV Community

Cover image for How to send an automated email via Google Script?
Shiva Aryal
Shiva Aryal

Posted on

How to send an automated email via Google Script?

To send an automated email via Google Script, you will need to do the following:

  1. Go to script.google.com and sign in with your Google account.

  2. Click on the "New script" button. This will create a new blank script for you.

  3. Replace the existing code with the following code:

function sendEmail() {
  var email = "youremail@example.com";
  var subject = "This is the subject of the email";
  var body = "This is the body of the email";
  MailApp.sendEmail(email, subject, body);
}
Enter fullscreen mode Exit fullscreen mode
  1. Replace "youremail@example.com" with the email address you want to send the email to.

  2. Replace "This is the subject of the email" with the subject of the email you want to send.

  3. Replace "This is the body of the email" with the body of the email you want to send.

  4. Save the script by clicking on the "File" menu and then selecting "Save".

  5. Test the script by clicking on the "Run" menu and then selecting "sendEmail". This will send an email to the email address you specified.

  6. You can also use this script to send emails to multiple recipients by separating the email addresses with a comma, like this:

var email = "youremail@example.com, anotheremail@example.com";

You can also customize the email further by using the various options available in the MailApp.sendEmail() function. For example, you can add attachments to the email, specify a reply-to address, or set the name of the sender. You can find more information about these options in the Google Scripts documentation.

Top comments (1)

Collapse
 
pyabdo profile image
py-abdo

very interesting!