awesome-cordova-plugins/src/plugins/emailcomposer.ts

116 lines
2.9 KiB
TypeScript
Raw Normal View History

2016-07-08 06:58:21 +08:00
import { Cordova, Plugin } from './plugin';
declare var cordova: any;
2016-07-08 06:58:21 +08:00
/**
* @name Email Composer
* @description
*
* Requires Cordova plugin: cordova-plugin-email-composer. For more info, please see the [Email Composer plugin docs](https://github.com/katzer/cordova-plugin-email-composer).
*
* 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.
*
* @usage
* ```typescript
* import { EmailComposer } from 'ionic-native';
*
*
* EmailComposer.isAvailable().then((available: boolean) =>{
2016-04-06 20:06:46 +08:00
* 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
* EmailComposer.open(email);
*
* ```
*/
@Plugin({
plugin: 'cordova-plugin-email',
2016-04-05 22:24:50 +08:00
pluginRef: 'cordova.plugins.email',
repo: 'https://github.com/hypery2k/cordova-email-plugin',
platforms: ['Android', 'iOS']
})
export class EmailComposer {
/**
2016-04-06 20:06:46 +08:00
* Verifies if sending emails is supported on the device.
*
* @param app {string?} An optional app id or uri scheme.
* @returns {Promise<boolean>} 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) => {
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-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-06 20:06:46 +08:00
* Displays the email composer pre-filled with data.
*
* @param email {Email} Email
2016-04-06 20:06:46 +08:00
* @param scope {any?} An optional scope for the promise
* @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-07-08 06:58:21 +08:00
static open(email: Email, scope?: any): Promise<any> { return; }
}
2016-07-08 06:58:21 +08:00
export interface Email {
app?: string;
to?: string | Array<string>;
cc?: string | Array<string>;
bcc?: string | Array<string>;
attachments?: Array<any>;
subject?: string;
body?: string;
isHtml?: boolean;
2016-07-08 06:58:21 +08:00
}