cordova-email-plugin icon indicating copy to clipboard operation
cordova-email-plugin copied to clipboard

Not send email in IONIC 2

Open fredroo opened this issue 7 years ago • 3 comments

      sendEmail() {
          EmailComposer.isAvailable().then((available: boolean) =>{
              if(available) {
                  let email = {
                    to: '[email protected]',
                    subject: this.register.value.subject,
                    body: 'De: ' + this.register.value.name + '<br>E-mail:' + this.register.value.email + '<br>Mensagem: ' + this.register.value.message,
                    isHtml: true
                  };

                  EmailComposer.open(email);
              }
          });
      }

using in form this:

(ngSubmit)="sendEmail()"


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

fredroo avatar Mar 05 '17 13:03 fredroo

I think the issue is it doesn't recognize default email app. When I removed if(available) check then Android shows a drawer to choose from available email apps. Once app is chosen then it opens prefilled.

andrzejtemplin avatar Mar 05 '17 19:03 andrzejtemplin

I'm running it on iOS 10.2.1 with cordova 6.5.0. Returned 'available' is false, but EmailComposer.open(email) works anyway. Maybe something wrong with isAvailable method?

bjakubiak avatar Mar 12 '17 06:03 bjakubiak

I think this is because of the way Ionic Native implements the various methods of the plugin, using promises instead of callbacks. I had a similar problem to you, until I noticed that the plugin documentation on the Ionic website says that isAvailable resolves a promise if true, and rejects it if false. So I tried this:

this.emailComposer.isAvailable().then( () => {
	// the promise is resolving in this function, so sending is available
	this.emailComposer.open( {
		subject: 'Email subject',
		body: 'Email body',
		isHtml: false
	} );
}, () => {
	// the promise is being rejected here, sending is not available
	// do some sort of error code
} );

It seems to work, on Android at least - but my iOS 10 device never seems to report having an email account configured.

gazchap avatar Jun 05 '17 20:06 gazchap