Building apps at a large company? Check out Ionic Enterprise

Email Composer

Improve this doc

Requires Cordova plugin: cordova-plugin-email-composer. For more info, please see the Email Composer plugin docs.

Repo: https://github.com/katzer/cordova-plugin-email-composer

Installation

  1. Install the Cordova and Ionic Native plugins:
    $ ionic cordova plugin add cordova-plugin-email-composer
    $ npm install --save @ionic-native/email-composer
    
  2. Add this plugin to your app's module

Supported platforms

Usage

import { EmailComposer } from '@ionic-native/email-composer';

constructor(private emailComposer: EmailComposer) { }

...


this.emailComposer.isAvailable().then((available: boolean) =>{
 if(available) {
   //Now we know we can send
 }
});

let email = {
  to: '[email protected]',
  cc: '[email protected]',
  bcc: ['[email protected]', '[email protected]'],
  attachments: [
    'file://img/logo.png',
    'res://icon.png',
    'base64:icon.png//iVBORw0KGgoAAAANSUhEUg...',
    'file://README.pdf'
  ],
  subject: 'Cordova Icons',
  body: 'How are you? Nice greetings from Leipzig',
  isHtml: true
};

// Send a text message using default options
this.emailComposer.open(email);

You can also assign aliases to email apps

// add alias
this.email.addAlias('gmail', 'com.google.android.gm');

// then use alias when sending email
this.email.open({
  app: 'gmail',
  ...
});

Instance Members

isAvailable(app)

Verifies if sending emails is supported on the device.

Param Type Details
app string

App id or uri scheme.Optional

Returns: Promise<any> Resolves if available, rejects if not available

requestPermission()

Request permission to access email accounts information

Returns: Promise<boolean> returns a promise that resolves with a boolean that indicates if the permission was granted

hasPermission()

Checks if the app has a permission to access email accounts information

Returns: Promise<boolean> returns a promise that resolves with a boolean that indicates if the permission was granted

addAlias(alias, packageName)

Adds a new mail app alias.

Param Type Details
alias string

The alias name

packageName string

The package name

open(options, scope)

Displays the email composer pre-filled with data.

Param Type Details
options EmailComposerOptions

Email

scope any

Scope for the promiseOptional

Returns: Promise<any> Resolves promise when the EmailComposer has been opened

EmailComposerOptions

Param Type Details
app string

App to send the email with

(optional)
to string | Array<string>

Email address(es) for To field

(optional)
cc string | Array<string>

Email address(es) for CC field

(optional)
bcc string | Array<string>

Email address(es) for BCC field

(optional)
attachments string[]

File paths or base64 data streams

(optional)
subject string

Subject of the email

(optional)
body string

Email body (for HTML, set isHtml to true)

(optional)
isHtml boolean

Indicates if the body is HTML or plain text

(optional)

API

Native

General