2
votes

I have a google spreadsheet that contains a list of email addresses. It's a contact list of sorts. I would like to have a function that opens a gmail new mail message window with these adresses (or some sub-set of them) so I can then complete the email and send.

The Sending Email tutorial on Google Developers shows you how to create and send emails directly, but not how open gmail ready for further editing.

Having looked at the reference for MailApp it seems that I can only use it to send completed emails, while GMailApp seems to allow me to access existing gmail messages.

Is there a way I can start gmail with a new message window without sending it?

3
Thanks for all the replies. I have managed to get it to work in a few different ways. 1) I created a new sheet with cells for to, subject and message along with a graphic button. The button had a function attached that gathered the bits of the email together and they are sent using the MailApp.sendMailBarbieBear

3 Answers

2
votes

There is no way for Google Apps Script to interact with the GMail User Interface.

An alternative would be to produce a mailto: link with a prefilled message URL, and present that to the user in a dialog or sidebar in your spreadsheet. When the link is clicked, it should open a new message window.

2
votes

yes this is (sort of) possible.

  1. make a webapp with a button to create the email.
  2. create a draft email as you wish using the gmail api in advanced services (see How to use the Google Apps Script code for creating a Draft email (from 985)?)
  3. provide a link in your webapp to open the drafts folder. Alternatively you might be able to use the gmail api to find the draft message id and build a url that directly opens the single draft message (haven't tried that with drafts, might not be possible)

"sort of" because the part you cant do is open the drafts window (or single message) automatically, the user must click something that opens the final link.

Advantage: more flexibility on your email body content, inline images and attachments.

Disadvantage: one more click and possibly only being able to open the drafts folder (and not the single draft directly)

0
votes

Thanks for your suggestions. It seems that there are several work arounds.

As my email needs are repetitively simple I ended up using a function that opens a really simple dialog box, with a text boxs for reciepients (which I can prepopulate if necessary) and subject and a text area for the message. The send button handler calls MailApp.sendEmail.