Oct 26, 2018

Google app script email example

function emailMe() {
  // Get the email address of the active user - that's you.
  var email = Session.getActiveUser().getEmail();

  // email subject line.
  var subject = 'your email subject';

  // email body.
  var body = 'your email body';

  // Send yourself an email with a link to the document.
  GmailApp.sendEmail(email, subject, body);
}

// Script-as-app template.
function doGet() {
  var app = UiApp.createApplication();

  var button = app.createButton('Email Me');
  app.add(button);

  var label = app.createLabel('An email was sent to you.')
                 .setId('statusLabel')
                 .setVisible(false);
  app.add(label);

  var handler = app.createServerHandler('myClickHandler');
  handler.addCallbackElement(label);
  button.addClickHandler(handler);

  return app;
}

function myClickHandler(e) {
  emailMe();
  var app = UiApp.getActiveApplication();

  var label = app.getElementById('statusLabel');
  label.setVisible(true);

  app.close();
  return app;
}