2017-03-20 16:38:14 -04:00
import { Injectable } from '@angular/core' ;
2018-04-06 22:38:59 +02:00
import {
Cordova ,
CordovaCheck ,
IonicNativePlugin ,
2018-09-17 18:23:18 +02:00
Plugin ,
getPromise
2018-04-06 22:38:59 +02:00
} from '@ionic-native/core' ;
2016-07-08 00:58:21 +02:00
2016-12-06 09:09:00 -05:00
export interface EmailComposerOptions {
2017-07-07 19:13:45 -04:00
/**
* App to send the email with
*/
2016-12-06 08:02:00 -05:00
app? : string ;
2017-07-07 19:13:45 -04:00
/**
* Email address(es) for To field
*/
2018-09-17 16:05:37 +02:00
to? : string | string [ ] ;
2016-12-06 08:02:00 -05:00
2017-07-07 19:13:45 -04:00
/**
* Email address(es) for CC field
*/
2018-09-17 16:05:37 +02:00
cc? : string | string [ ] ;
2016-12-06 08:02:00 -05:00
2017-07-07 19:13:45 -04:00
/**
* Email address(es) for BCC field
*/
2018-09-17 16:05:37 +02:00
bcc? : string | string [ ] ;
2016-12-06 08:02:00 -05:00
2017-07-07 19:13:45 -04:00
/**
* File paths or base64 data streams
*/
attachments? : string [ ] ;
2016-12-06 08:02:00 -05:00
2017-07-07 19:13:45 -04:00
/**
* Subject of the email
*/
2016-12-06 08:02:00 -05:00
subject? : string ;
2017-07-07 19:13:45 -04:00
/**
* Email body (for HTML, set isHtml to true)
*/
2016-12-06 08:02:00 -05:00
body? : string ;
2017-07-07 19:13:45 -04:00
/**
* Indicates if the body is HTML or plain text
*/
2016-12-06 08:02:00 -05:00
isHtml? : boolean ;
2018-04-06 22:38:59 +02:00
/**
* Content type of the email (Android only)
*/
type ? : string ;
2016-12-06 08:02:00 -05:00
}
2016-04-05 21:55:24 +10:00
/**
* @name Email Composer
* @description
*
2016-09-25 20:01:39 -03: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 21:55:24 +10:00
*
2016-06-11 10:58:44 -04:00
*
2016-04-05 21:55:24 +10:00
* @usage
2016-07-20 17:17:09 +02:00
* ```typescript
2018-10-10 16:13:45 -05:00
* import { EmailComposer } from '@ionic-native/email-composer/ngx';
2016-04-05 21:55:24 +10:00
*
2017-03-20 16:38:14 -04:00
* constructor(private emailComposer: EmailComposer) { }
2016-04-29 23:56:49 -04:00
*
2017-03-20 16:38:14 -04:00
* ...
*
*
* this.emailComposer.isAvailable().then((available: boolean) =>{
2016-04-06 22:06:46 +10:00
* if(available) {
* //Now we know we can send
* }
* });
2016-04-05 21:55:24 +10: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
2017-12-28 07:28:44 -05:00
* }
2016-04-05 21:55:24 +10:00
*
* // Send a text message using default options
2017-03-20 16:38:14 -04:00
* this.emailComposer.open(email);
2017-07-07 19:13:45 -04:00
* ```
2016-04-05 21:55:24 +10:00
*
2017-07-07 19:13:45 -04:00
* You can also assign aliases to email apps
* ```ts
* // add alias
* this.email.addAlias('gmail', 'com.google.android.gm');
*
* // then use alias when sending email
* this.email.open({
* app: 'gmail',
* ...
* });
2016-04-05 21:55:24 +10:00
* ```
2016-12-06 09:09:00 -05:00
* @interfaces
* EmailComposerOptions
2016-04-05 21:55:24 +10:00
*/
@Plugin ( {
2016-10-27 12:48:50 -05:00
pluginName : 'EmailComposer' ,
2017-07-07 19:13:45 -04:00
plugin : 'cordova-plugin-email-composer' ,
2016-04-06 00:24:50 +10:00
pluginRef : 'cordova.plugins.email' ,
2017-07-07 19:13:45 -04:00
repo : 'https://github.com/katzer/cordova-plugin-email-composer' ,
2018-04-06 22:38:59 +02:00
platforms : [ 'Amazon Fire OS' , 'Android' , 'Browser' , 'iOS' , 'Windows' , 'macOS' ]
2016-04-05 21:55:24 +10:00
} )
2017-03-20 16:38:14 -04:00
@Injectable ( )
2017-04-27 00:36:12 -04:00
export class EmailComposer extends IonicNativePlugin {
2018-09-18 16:24:05 +02:00
/**
* Checks if the app has a permission to access email accounts information
* @return {Promise<boolean>} returns a promise that resolves with a boolean that indicates if the permission was granted
*/
@Cordova ( {
successIndex : 0 ,
errorIndex : 2
} )
hasPermission ( ) : Promise < boolean > {
return ;
}
/**
* Request permission to access email accounts information
* @return {Promise<boolean>} returns a promise that resolves with a boolean that indicates if the permission was granted
*/
@Cordova ( {
successIndex : 0 ,
errorIndex : 2
} )
requestPermission ( ) : Promise < boolean > {
return ;
}
2016-04-29 23:56:49 -04:00
/**
2016-04-06 22:06:46 +10:00
* Verifies if sending emails is supported on the device.
2016-04-29 23:56:49 -04:00
*
2018-04-08 21:21:37 +02:00
* @param {string} [app] App id or uri scheme.
2016-11-29 16:40:50 -06:00
* @returns {Promise<any>} Resolves if available, rejects if not available
2016-04-06 22:06:46 +10:00
*/
2017-03-20 16:38:14 -04:00
@CordovaCheck ( )
isAvailable ( app? : string ) : Promise < any > {
2017-12-29 10:15:44 -05:00
return getPromise < boolean > ( ( resolve , reject ) = > {
2016-08-22 19:19:43 -03:00
if ( app ) {
2017-07-07 19:13:45 -04:00
EmailComposer . getPlugin ( ) . isAvailable ( app , ( isAvailable : boolean ) = > {
2016-08-22 19:19:43 -03:00
if ( isAvailable ) {
resolve ( ) ;
} else {
reject ( ) ;
}
} ) ;
} else {
2017-07-07 19:13:45 -04:00
EmailComposer . getPlugin ( ) . isAvailable ( ( isAvailable : boolean ) = > {
2016-08-22 19:19:43 -03:00
if ( isAvailable ) {
resolve ( ) ;
} else {
reject ( ) ;
}
} ) ;
}
2016-04-06 22:06:46 +10:00
} ) ;
}
2016-04-05 21:55:24 +10:00
2017-07-07 19:13:45 -04:00
/**
2018-09-18 16:24:05 +02:00
* Displays the email composer pre-filled with data.
*
* @param {EmailComposerOptions} options Email
* @param {any} [scope] Scope for the promise
* @returns {Promise<any>} Resolves promise when the EmailComposer has been opened
2017-07-07 19:13:45 -04:00
*/
@Cordova ( {
2018-09-18 16:24:05 +02:00
successIndex : 1 ,
errorIndex : 3
2017-07-07 19:13:45 -04:00
} )
2018-09-18 16:24:05 +02:00
open ( options : EmailComposerOptions , scope? : any ) : Promise < any > {
2017-12-28 07:28:44 -05:00
return ;
}
2017-07-07 19:13:45 -04:00
2016-04-06 22:06:46 +10:00
/**
* Adds a new mail app alias.
*
2018-04-08 21:21:37 +02:00
* @param {string} alias The alias name
* @param {string} packageName The package name
2016-04-06 22:06:46 +10:00
*/
2016-04-06 00:24:50 +10:00
@Cordova ( )
2018-04-06 22:38:59 +02:00
addAlias ( alias : string , packageName : string ) : void { }
2016-04-05 21:55:24 +10:00
}