0
votes

I have a Spreadsheet connected to a Google Form that gets email addresses from people who submit the form. I already have a menu item that gets the email address from the cell, composes an email, and sends it.

function onOpen() {
  var ui = SpreadsheetApp.getUi();
  ui.createMenu('Send E-mail')
      .addItem('Selected E-mail', 'selected_email')
      .addToUi();
}

function selected_email() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var email = sheet.getActiveCell().getValue();
  GmailApp.sendEmail(email, "Your Suggestion", "");
}

However, I would like to be able to edit the message as I choose without having to change the script.

Is there a way to create a popup "Compose Message" box like the one in Gmail using Google Apps Script?

Thank you in advance.

1
The answer would be yes but....no.- You will be able to create a pre-filled text area with text you can edit but you won't have all the formatting and image insertion features you can have in Gmail. In other words, it will be fairly basic. If you show the code you use we could suggest a code implementation.Serge insas
@Sergeinsas Could you please be a little more descriptive? Thanks.NTwers
Serge said pretty much all there is to say with the information you provided; what part are you confused about?Tim
Look the Class Browser, I think you can do this. developers.google.com/apps-script/reference/base/browserHann
@Tim I'm quite new at this, so I wasn't clear on what he meant of yes and no.NTwers

1 Answers

0
votes

Based on some of the comments to the question, I was able to figure out how to solve my own question.

function onOpen() {
  var ui = SpreadsheetApp.getUi();
  ui.createMenu('Send E-mail')
      .addItem('Selected E-mail', 'selected_email')
      .addToUi();
}

function selected_email() {
  var aliases = GmailApp.getAliases();
  var desiredAlias = aliases[/*Any Number*/];
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var email = sheet.getActiveCell().getValue();
  var message = Browser.inputBox("Message Composer", "Compose E-mail:", Browser.Buttons.OK_CANCEL);
  GmailApp.sendEmail(email, "Your Suggestion", message, {from: desiredAlias});
}

The GmailApp.sendEmail has multiple implementations, one of which has an 'options' parameter. In this, you can set from whom you want to send the email, provided you have access to that account. This can be done by getting the aliases of your account.

In order to enable the user to enter their own text, there is an inputBox method that's part of the Browser class that allows the user to store any text as a variable in the program. By doing this, you can create a quasi "Compose E-mail" box, and use that inputted text as your e-mail message.

Thanks to @Sergeinsas and @Hann for their help!