2016-07-08 06:58:21 +08:00
|
|
|
import { Cordova, Plugin } from './plugin';
|
|
|
|
|
2016-06-11 23:07:19 +08:00
|
|
|
declare var cordova: any;
|
2016-07-08 06:58:21 +08:00
|
|
|
|
2016-12-06 22:09:00 +08:00
|
|
|
export interface EmailComposerOptions {
|
2016-12-06 21:02:00 +08:00
|
|
|
|
|
|
|
app?: string;
|
|
|
|
|
|
|
|
to?: string | Array<string>;
|
|
|
|
|
|
|
|
cc?: string | Array<string>;
|
|
|
|
|
|
|
|
bcc?: string | Array<string>;
|
|
|
|
|
|
|
|
attachments?: Array<any>;
|
|
|
|
|
|
|
|
subject?: string;
|
|
|
|
|
|
|
|
body?: string;
|
|
|
|
|
|
|
|
isHtml?: boolean;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-05 19:55:24 +08:00
|
|
|
/**
|
2017-01-10 20:41:44 +08:00
|
|
|
* @beta
|
2016-04-05 19:55:24 +08:00
|
|
|
* @name Email Composer
|
|
|
|
* @description
|
|
|
|
*
|
2016-09-26 07:01:39 +08:00
|
|
|
* Requires Cordova plugin: cordova-plugin-email-composer. For more info, please see the [Email Composer plugin docs](https://github.com/hypery2k/cordova-email-plugin).
|
2016-04-05 19:55:24 +08:00
|
|
|
*
|
2016-06-11 22:58:44 +08:00
|
|
|
* DISCLAIMER: This plugin is experiencing issues with the latest versions of Cordova. Use at your own risk. Functionality is not guaranteed. Please stay tuned for a more stable version.
|
2016-08-11 19:55:26 +08:00
|
|
|
* A good alternative to this plugin is the social sharing plugin.
|
2016-06-11 22:58:44 +08:00
|
|
|
*
|
2016-04-05 19:55:24 +08:00
|
|
|
* @usage
|
2016-07-20 23:17:09 +08:00
|
|
|
* ```typescript
|
|
|
|
* import { EmailComposer } from 'ionic-native';
|
2016-04-05 19:55:24 +08:00
|
|
|
*
|
2016-04-30 11:56:49 +08:00
|
|
|
*
|
2016-07-20 23:17:09 +08:00
|
|
|
* EmailComposer.isAvailable().then((available: boolean) =>{
|
2016-04-06 20:06:46 +08:00
|
|
|
* if(available) {
|
|
|
|
* //Now we know we can send
|
|
|
|
* }
|
|
|
|
* });
|
2016-04-05 19:55:24 +08:00
|
|
|
*
|
|
|
|
* 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
|
2016-05-21 01:57:00 +08:00
|
|
|
* EmailComposer.open(email);
|
2016-04-05 19:55:24 +08:00
|
|
|
*
|
|
|
|
* ```
|
2016-12-06 22:09:00 +08:00
|
|
|
* @interfaces
|
|
|
|
* EmailComposerOptions
|
2016-04-05 19:55:24 +08:00
|
|
|
*/
|
|
|
|
@Plugin({
|
2016-10-28 01:48:50 +08:00
|
|
|
pluginName: 'EmailComposer',
|
2016-09-25 05:00:44 +08:00
|
|
|
plugin: 'cordova-plugin-email',
|
2016-04-05 22:24:50 +08:00
|
|
|
pluginRef: 'cordova.plugins.email',
|
2016-09-25 05:00:44 +08:00
|
|
|
repo: 'https://github.com/hypery2k/cordova-email-plugin',
|
|
|
|
platforms: ['Android', 'iOS']
|
2016-04-05 19:55:24 +08:00
|
|
|
})
|
|
|
|
export class EmailComposer {
|
2016-04-30 11:56:49 +08:00
|
|
|
|
|
|
|
/**
|
2016-04-06 20:06:46 +08:00
|
|
|
* Verifies if sending emails is supported on the device.
|
2016-04-30 11:56:49 +08:00
|
|
|
*
|
2016-05-21 02:06:13 +08:00
|
|
|
* @param app {string?} An optional app id or uri scheme.
|
2016-11-30 06:40:50 +08:00
|
|
|
* @returns {Promise<any>} Resolves if available, rejects if not available
|
2016-04-06 20:06:46 +08:00
|
|
|
*/
|
2016-07-08 06:58:21 +08:00
|
|
|
static isAvailable(app?: string): Promise<any> {
|
2016-04-06 20:06:46 +08:00
|
|
|
return new Promise<boolean>((resolve, reject) => {
|
2016-08-23 06:19:43 +08:00
|
|
|
if (app) {
|
|
|
|
cordova.plugins.email.isAvailable(app, (isAvailable) => {
|
|
|
|
if (isAvailable) {
|
|
|
|
resolve();
|
|
|
|
} else {
|
|
|
|
reject();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
cordova.plugins.email.isAvailable((isAvailable) => {
|
|
|
|
if (isAvailable) {
|
|
|
|
resolve();
|
|
|
|
} else {
|
|
|
|
reject();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-04-06 20:06:46 +08:00
|
|
|
});
|
|
|
|
}
|
2016-04-05 19:55:24 +08:00
|
|
|
|
2016-04-06 20:06:46 +08:00
|
|
|
/**
|
|
|
|
* Adds a new mail app alias.
|
|
|
|
*
|
|
|
|
* @param alias {string} The alias name
|
|
|
|
* @param packageName {string} The package name
|
|
|
|
*/
|
2016-04-05 22:24:50 +08:00
|
|
|
@Cordova()
|
2016-07-08 06:58:21 +08:00
|
|
|
static addAlias(alias: string, packageName: string): void { }
|
2016-04-30 11:56:49 +08:00
|
|
|
|
2016-04-05 19:55:24 +08:00
|
|
|
/**
|
2016-04-06 20:06:46 +08:00
|
|
|
* Displays the email composer pre-filled with data.
|
2016-04-30 11:56:49 +08:00
|
|
|
*
|
2016-12-06 22:09:00 +08:00
|
|
|
* @param options {EmailComposerOptions} Email
|
2016-04-06 20:06:46 +08:00
|
|
|
* @param scope {any?} An optional scope for the promise
|
2016-04-05 19:55:24 +08:00
|
|
|
* @returns {Promise<any>} Resolves promise when the EmailComposer has been opened
|
|
|
|
*/
|
2016-04-05 22:24:50 +08:00
|
|
|
@Cordova({
|
|
|
|
successIndex: 1,
|
|
|
|
errorIndex: 3
|
|
|
|
})
|
2016-12-06 22:09:00 +08:00
|
|
|
static open(options: EmailComposerOptions, scope?: any): Promise<any> { return; }
|
2016-04-05 19:55:24 +08:00
|
|
|
|
|
|
|
}
|