I am creating a custom component for Lightning for Gmail.

I want to read the content of email body. I created a test component and a controller for it.

<aura:component implements="clients:availableForMailAppAppPage,clients:hasItemContext">
    <aura:attribute name="messageBody" type="String" />
    <ui:button label="Click" press="{!c.myAction}"/>

myAction : function(component, event, helper) {

But in the console after clicking my button I see only "undefined".

At the same time, if for example I add to the controller console.log(component.get("v.people").from.name);, then in the console I can see the sender's name.

Also I tried to remove from the code line <aura:attribute name="messageBody" type="String" />, but nothing has changed.

What am I doing wrong?


the message body and people are populated at some point after your component has been created. A few suggested changes to your code:

  • Any attributes on an interface that you implement you do not need to specify in your component.
  • You'll want to listen to "change" events on the attributes you care about: <aura:handler name="change" value="{!v.people}" action="{!c.peopleChanged}" /> That will listen to changes to the people attribute. Your component is first created and then these attribute values are populated.
  • You can also do things like cmp.get('v.people.from.email') that will automatically check for null/undefined for you.

I hope this helps.

  • Thanks, Braden.I did as you said and event handler <aura:handler name="change" value="{!v.people}" action="{!c.peopleChanged}" /> is triggered, but event handler <aura:handler name="change" value="{!v.messageBody}" action="{!c.bodyChanged}" /> does not work. Any other ideas? – Vladimir Mar 31 '17 at 9:55
  • Hmm, that is strange, I copied your button and handler logic and was able to try this myself and it worked. Here's the source from my component: gist.github.com/nedarb/315464ae529ebad4c85280461b6b4fe9 – Braden Hays Apr 3 '17 at 20:27
  • I created a new component, copied your code and created another page for GMAIL. But I still see "undefined" in log instead of the email body. This is really strange. i64.tinypic.com/2j4f4ew.png – Vladimir Apr 4 '17 at 6:53
  • At github.com the code is named "Custom Salesforce Lightning for Outlook component". Maybe you tried this code for Outlook, not for Gmail? – Vladimir Apr 4 '17 at 7:06
  • You are correct. This is in fact not working as it should. Let me poke around a little and figure out what's going on here. – Braden Hays Apr 5 '17 at 16:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.