Composing emails in a NativeScript app

Brad Martin
InstructorBrad Martin
Share this video with your friends

Social Share Links

Send Tweet
Published 7 years ago
Updated 5 years ago

We will use the NativeScript-Email plugin from Eddy Verbruggen to compose email messages from our app that the user can send out.

[00:01] We'll start by adding the plugin using the tns plugin add command. The name of the plugin is nativescript-email. Now that we have the plugin installed we'll just add a stack-layout to the page. Inside of stack-layout we're just going to add a button to fire off the event with the plugin.

[00:23] We use the tap event on the button to execute our function. We'll name of the function openEmail. Now that we have a button on the main-page.xml for the interface, we'll move to the main-page.ts, for the code behind for the interface.

[00:41] First thing is we'll import the entire email plugin. Next we need to define the function that was set on the tap event of the button, we named it openEmail. The first thing you want to do before sending an email is check the device and make sure it's capable of sending email.

[01:08] The plugin actually provides the available method, which we can call, and it returns a promise and the result is a Boolean. If this result is true, we know we can send an email on this device.

[01:32] Now that we know we can send an email, we can use the compose method from the plugin, which is expecting an object type of the compose options which is provided by the plugin as an interface. First property we'll set as the subject, just say test. The body, "Hello, egghead."

[01:55] The to property accepts an array of strings, we're just going to send this to myself. There's also BCC and CC if you want to carbon copy, but we'll just keep it simple here. This also returns a promise. We'll just log the result here.

[02:34] Now when we tap the button we're going to execute the openEmail function, which first we're going to check if the email capability is possible on this device. If the result returns true, then we call the compose method which should open up a dialog to open up the email application on the device, and should pre-fill the email subject, the body, and the to property.

[02:59] We'll go ahead and tap the button, and we're presented with the Android action sheet. We're going to go ahead and select the Inbox application.

[03:08] There you see the to address is filled, the subject, and the body. You can also send attachments in the options object for the compose method.

~ 2 hours ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today