Create an Email as a Quick Action

In a custom component, create a button to launch the email composer with pre-populated content. To launch a record create a page with pre-populated field values, use the lightning:pageReferenceUtils and lightning:navigation components together.

These examples show you how to do this using standard actions and override actions.

Launch the QuickAction (Global) Send Email action from a custom component. Quick/Standard Actions can be called using page references and the navigation service API in any custom Aura component.

Define Navigation Services, pageReference Utils, and Action Button

Define the navigation services, the pageReference utils, and the action button in component markup.
1<lightning:navigation aura:id="navService"/>
2<lightning:pageReferenceUtils aura:id="pageRefUtil"/>
3<div>
4    <lightning:button label="Send an " value="Global.SendEmail" onclick="{! c.openPageRefModal}"/>
5</div>

Pass Attributes in pageReference to navService

Pass in the appropriate attributes in pageReference to navService.

1openPageRefModal: function (cmp, event, helper) {
2        
3    var navService = cmp.find("navService");
4    var actionApiName = event.getSource().get('v.value');
5    var pageRef = {
6        type: "standard__quickAction",
7        attributes: {
8            apiName : actionApiName
9        },
10        state: {
11            recordId : '003xx000004WhEiAAK',
12        }
13    };
14
15    navService.navigate(pageRef);
16}

Add Predefined Fields Info

Allow the user to pass action field data as part of the pageReference attributes with the fieldOverride payload.

This code is an example of what a pageReference request could look like:

1openPageRefModal: function (cmp, event, helper) {
2    var navService = cmp.find("navService");
3    var actionApiName = event.getSource().get('v.value');
4    var pageRef = {
5        type: "standard__quickAction",
6        attributes: {
7            apiName : actionApiName
8        },
9        state: {
10            recordId : '003xx000004WhTJAA0'
11        }
12    };
13    var defaultFieldValues = {
14        HtmlBody: "Monthly Review",
15        Subject : "Monthly Review"
16    }
17    pageRef.state.defaultFieldValues = cmp.find("pageRefUtil").encodeDefaultFieldValues(defaultFieldValues);
18
19    navService.navigate(pageRef);
20}

Default Email Field Values

By default, Salesforce prepopulates the To field with a contact or lead email address when you open the email action from the contact or lead record home pages. Ensure that the fields you specify in the encodeDefaultFieldValues function aren’t Read-Only in the Send Email global action’s layout. If the HTML Body and Subject fields are Read-Only, the email draft doesn’t include pre-populated text for those fields.

These fields are supported:

  • FromAddress
  • ToAddress
  • CCAddress
  • BccAddress
  • Subject
  • HTMLBody
  • RelatedToId

The FromAddress field is set to the logged in user's email address. The Subject and HTMLBody are not set by default.

Only fields that are available on the email quick action are supported. For example, AttachmentId and ContentDocumentIds aren't supported as they are not part of the email quick action layout.

For more information on the supported fields, see Object Reference for the Salesforce Platform: EmailMessage.