2

We are developing a Gmail Addon in which we extend the compose UI.

This extends the compose window in which you can compose your e-mail.

We need the 'From', 'To', 'Subject' and 'Body' of the message that is being composed.

The 'From' can be read from the Session object like this

var mySelf = Session.getEffectiveUser().getEmail();

The 'To' can be read from the draftMetadata from the event object of the function being called.

function composeEmail(event) { console.log(event.draftMetadata.toRecipients); }

The 'Subject' and 'Body' can't be read from the event object of the function since it is a composeTrigger. The argument contains these objects:

{
  formInput = {}, 
  clientPlatform = web, 
  formInputs = {}, 
  parameters = {}, 
  draftMetadata = {
    toRecipients = [test @test.com],
    subject = ,
    bccRecipients = [],
    ccRecipients = []
  }
}

Surprisingly to me, the subject key is there but not being filled in (yes I did type in a subject).

Question:

How can I get the 'Subject' and 'Body' of the E-mail being composed by the user in the extended composer UI?

Extra information:

The contextual trigger action contains the following object as event object:

{
  clientPlatform = web, 
  messageMetadata = {
    messageId = 16e agg7323451256989f68,
    accessToken = AAGdOAawdaAOW8PWchmdawdk0N13STKnBPMAOXVjZVHyQMfAawdBtgEIrS6N8y5h2BOZnKFPlfsl5VBsyPiF7YiONOoP7XVjKZawdi - E6vI - jVU92dPmfj3RNmXfawdawdeaNMrXehAFLm
  }
}

By reading an email through the contextual trigger a messageId is being added in which the getBody and getSubject methods can be used.

2 Answers2

2

As of now, the Compose Trigger Event never returns the value of the subject field.

I have filled a bug for this here. Click the ★ icon to follow this Issue and get updates. This will also help prioritize this Issue.

As a workaround, you can use the contextual trigger to:

  1. Get the messageId
  2. Find drafts that have that messageId associated to them
  3. Get the draft by their draftId
  4. Fetch the subject line from the Headers object on the draft.

This only works on drafts that are replying to a specific message.

Raserhin
  • 2,516
  • 1
  • 10
  • 14
  • Hi Raserhin, thank you for filling in the issue. I have starred the issue to help prioritize the issue. The contextual trigger is an option indeed for only replying. We do really need it when composing a message aswell, which seems no option to do so for now. – Daniël Leushuis Nov 28 '19 at 07:53
  • This seems to be fixed now so I can see read `gmail.subject` property. It is so utterly bizarre and disappointing though that I cannot access the message for which the reply was created inside compose. The `contextualTriggers` lets me do all kinds of clever things since I can tell what the source message is. Even with the full `https://www.googleapis.com/auth/gmail.readonly` scope I can't see the 'replyTo' message under compose. Don't really understand the point of the compose UI if it can't be dynamic :-( – Simon_Weaver Dec 29 '20 at 08:07
0

I've never done this before so this is a guess. I looked at the compose dialog html with the developer tools and this is what I noticed.

enter image description here

There seem to be a bunch of hidden inputs that are used to store values that are typed into the compose dialog. So I would try something like: formInputs.body or perhaps formInput.body taking the name of the key from names of this hidden elements. This is just a guess.

Cooper
  • 59,616
  • 6
  • 23
  • 54
  • Hi Cooper, thank you for your guess. The code of the App Script is being executed in the back-end so any client-side variables like `window` or `document` aren't available. This way there is no possibility to read anything from the rendered front-end – Daniël Leushuis Nov 28 '19 at 07:54