cordova-email-plugin
cordova-email-plugin copied to clipboard
Not send email in IONIC 2
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.
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.
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?
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.