DEV Community

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

Posted on

5 2 2 2 2

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.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (1)

Collapse
 
pyabdo profile image
py-abdo

very interesting!

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay