Email Composer
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
- Install the Cordova and Ionic Native plugins:
$ ionic cordova plugin add cordova-plugin-email-composer $ npm install --save @ionic-native/email-composer@4
- Add this plugin to your app's module
Supported platforms
- Amazon Fire OS
- Android
- Browser
- iOS
- Windows
- macOS
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: 'max@mustermann.de',
cc: 'erika@mustermann.de',
bcc: ['john@doe.com', 'jane@doe.com'],
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
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
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
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
open(options, scope)
Displays the email composer pre-filled with data.
Param | Type | Details |
---|---|---|
options |
EmailComposerOptions
|
|
scope |
any
|
Scope for the promiseOptional |
Returns: Promise<any>
Resolves promise when the EmailComposer has been opened
addAlias(alias, packageName)
Adds a new mail app alias.
Param | Type | Details |
---|---|---|
alias |
string
|
The alias name |
packageName |
string
|
The package name |
EmailComposerOptions
Param | Type | Details |
---|---|---|
app |
string
|
App to send the email with (optional) |
to |
string | string[]
|
Email address(es) for To field (optional) |
cc |
string | string[]
|
Email address(es) for CC field (optional) |
bcc |
string | 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) |
type |
string
|
Content type of the email (Android only) (optional) |