Nechemya Kanelsky
Nechemya Kanelsky

Reputation: 673

Filter apps of Cordova's Email Composer

I use this plugin: http://ngcordova.com/docs/plugins/emailComposer/

This is my angular code:

$scope.report = function(){
    var CEO_EMAIL_ADDRESS = '[email protected]';

    $cordovaEmailComposer.isAvailable().then(function() {
        $cordovaEmailComposer.open({
            to: CEO_EMAIL_ADDRESS,
            subject:  langTranslateService.getData('REPORT_A_PROBLEM'),
            body: '',
            isHtml: false
        });
    });
};

I need only the phone email will be opened or the option to choose from email applications only.

Why there is "bluetooth, dropbox..." in the options?

Can I change it..?

popup options

Upvotes: 2

Views: 636

Answers (1)

Philip Bijker
Philip Bijker

Reputation: 5115

According to the plugin specification found here, you should be able to supply an app option to the open method to target a specific app for opening the email draft (at the time of writing Android only).

First an alias should be made for the desired app like so:

cordova.plugins.email.addAlias('outlook', 'com.microsoft.android.outlook');

This example creates an alias outlook for the Outlook app. The second parameter is the package name of the app, which I was able to find by installing a plugin like Package Name Viewer.

You can validate if the app is available with the following overload of the isAvailable function:

cordova.plugins.email.isAvailable(
    'outlook', function (isAvailable, withScheme) {
        // isAvailable indicates if sending emails is available at all
        // withScheme is true if the desired app/scheme is available. When false the fallback of choosing an approriate app is applied
    }
);

Then you can supply this alias to the open method like in the example below:

$cordovaEmailComposer.open({
    app: 'outlook',
    to: CEO_EMAIL_ADDRESS,
    subject:  langTranslateService.getData('REPORT_A_PROBLEM'),
    body: '',
    isHtml: false
});

Now the draft should open in Outlook when available. Give it a try!

Upvotes: 1

Related Questions