3

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?

BarbieBear
  • 175
  • 3
  • 10
  • 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.sendMail – BarbieBear Nov 12 '15 at 07:00

3 Answers3

2

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.

Community
  • 1
  • 1
Mogsdad
  • 44,709
  • 21
  • 151
  • 275
  • thanks. I thought that might be the case. I suppose another alternative would be a form to capture the mail message and title and then use MailApp.sendEmail. – BarbieBear Nov 05 '15 at 15:00
  • Yes - that would also do it, but would be more work and possibly less familiar to the user. – Mogsdad Nov 05 '15 at 15:09
  • Thanks a lot for the suggestion. I find this works really well and is my preferred solution of a few I tried. I combined the URL with the example used in an answer to this [Google app script to open a url](http://stackoverflow.com/questions/10744760/google-apps-script-to-open-a-url). Note that the actual url given in the prefill link does not work but someone givesa correction in the comments – BarbieBear Nov 12 '15 at 07:09
2

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)

Community
  • 1
  • 1
Zig Mandel
  • 19,571
  • 5
  • 26
  • 36
0

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.

BarbieBear
  • 175
  • 3
  • 10