Email Composer
EOL Notice
Email Composer will reach its end-of-life on July 1, 2024, and will no longer receive updates or support. Please see Support Policy for additional information.
The Email Composer plugin provides the ability to programmatically create and send emails from within an app.
Installation
If you have not already setup Ionic Enterprise in your app, follow the one-time setup steps.
Next, install the plugin:
- Capacitor
- Cordova
npm install @ionic-enterprise/email-composer
npx cap sync
ionic cordova plugin add @ionic-enterprise/email-composer
Using with AndroidX Projects (Android)
This plugin relies on the legacy Android Support libraries and will not work in projects using the newer AndroidX libraries without using the jetifier tool to patch them.
npm install jetifier
npx jetifier
To run it automatically when dependencies are installed, add "postinstall": "jetifier"
in the package.json
.
Index
Classes
Interfaces
Classes
EmailComposer
usage:
import { EmailComposer } from '@ionic-enterprise/email-composer/ngx';
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',
...
});
interfaces: EmailComposerOptions
addAlias
▸ addAlias(alias: string
, packageName: string
): void
Adds a new mail app alias.
Parameters:
Name | Type | Description |
---|---|---|
alias | string | The alias name |
packageName | string | The package name |
Returns: void
getClients
▸ getClients(): Promise
<string
[]>
Returns an array of email clients installed on the device.
Returns: Promise
<string
[]>
Resolves if available, rejects if not available
hasAccount
▸ hasAccount(): Promise
<any
>
Verifies if an email account is configured on the device.
Returns: Promise
<any
>
Resolves if available, rejects if not available
hasClient
▸ hasClient(app: string
): Promise
<any
>
Verifies if a specific email client is installed on the device.
Parameters:
Name | Type |
---|---|
Optional app | string |
Returns: Promise
<any
>
Resolves if available, rejects if not available
hasPermission
▸ hasPermission(): Promise
<boolean
>
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
isAvailable
▸ isAvailable(app?: string
): Promise
<any
>
Verifies if sending emails is supported on the device.
Parameters:
Name | Type |
---|---|
Optional app | string |
Returns: Promise
<any
>
Resolves if available, rejects if not available
open
▸ open(options: EmailComposerOptions, scope?: any
): Promise
<any
>
Displays the email composer pre-filled with data.
Parameters:
Name | Type | Description |
---|---|---|
options | EmailComposerOptions | |
Optional scope | any |
Returns: Promise
<any
>
Resolves promise when the EmailComposer has been opened
requestPermission
▸ requestPermission(): Promise
<boolean
>
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
Interfaces
EmailComposerOptions
EmailComposerOptions:
<Optional>
app
● app: string
App to send the email with
<Optional>
attachments
● attachments: string
[]
File paths or base64 data streams
<Optional>
bcc
● bcc: string
| string
[]
Email address(es) for BCC field
<Optional>
body
● body: string
Email body (for HTML, set isHtml to true)
<Optional>
cc
● cc: string
| string
[]
Email address(es) for CC field
<Optional>
isHtml
● isHtml: boolean
Indicates if the body is HTML or plain text
<Optional>
subject
● subject: string
Subject of the email
<Optional>
to
● to: string
| string
[]
Email address(es) for To field
<Optional>
type
● type: string
Content type of the email (Android only)