$cordovaEmailComposer can not send mail

can not send mail with $cordovaEmailComposer
can any one please help

A more detailed explaination would be required for any of us to help. Doesnā€™t the composer open? Does it give any errors? Have you checked the console for any errors? What version of cordova are you using? Are you using Xwalk?

Thanks for the reply.
No the email composer does not open up.
Following my codes

var TestApp =angular.module(ā€˜TestAppā€™, [ā€˜ionicā€™,ā€˜ngStorageā€™,ā€˜ngCordovaā€™]);

$ionicPlatform.ready(function(){
$cordovaEmailComposer.isAvailable().then(function() {
var email = {
to: EmailAddr,
subject: ā€˜Cordova Iconsā€™,
body: ā€˜How are you? Nice greetings from Leipzigā€™,
isHtml: true
};

$cordovaEmailComposer.open(email).then(function () {
  alert('mailsend');
}),function () {
  alert('error');
}

}, function () {
alert(ā€˜Errorā€™)
});

})

Please help

does $cordovaEmailComposer.isAvailable() returns true? If not, is there an email account configured on the device?

Thanks @ubunny for the information. I will retest it and confirm.
One problem is that ngCordova plugin does not work on ionic serve command when it opens up in a browser. I have to connect my android cell phone to do the testing.
:disappointed:

I have changed my code
$ionicPlatform.ready(function() {
alert(ā€œ2ā€);
//document.addEventListener(ā€œdevicereadyā€, function () {
alert(ā€œ3ā€);
var email = {
to: EmailAddr,
subject: ā€˜Cordova Iconsā€™,
body: ā€˜How are you? Nice greetings from Leipzigā€™,
isHtml: true
};
$cordovaEmailComposer.open(email).then(function () {
alert(ā€œ5ā€);
alert(ā€˜mailsendā€™);
}), function () {
alert(ā€˜errorā€™);
}

alert 3 is working but alert 5 never shows up

please use console.log and the android debug monitor. This is no way of testing :slight_smile: Iā€™m pretty sure you will find the problem there

Hi,
I am testing my app connecting my android cell phone as a device. Please suggest how to use log and android debug monitor.
I am working on web storm.
Thanks.

just use console.log instead of alert. If you have adb installed, there should also be a android-sdk/tools/monitor on your system. That way you can view logs in runtime. Also, other errors will be shown there

Iā€™m not familiar with web storm but if youā€™re running via console/terminal you can use ionic run android --device -l -c. You can also use android device monitor on IDEs such as Eclipse and Android Studio.

Finally the problem is solved.:smiley:

To debug my code this time i use Visual Studio code and add a Cordova plugin in it
https://marketplace.visualstudio.com/items?itemName=vsmobile.cordova-tools

i remove my android platform and the all the mail sending libs.
Then run the following command again,
cordova plugin add https://github.com/katzer/cordova-plugin-email-composer.git
And then
ionic platform add android
I replace my code by the following,

$scope.SendMail=function(EmailAddr){
var email = {
to: EmailAddr,
subject: ā€˜Test Messageā€™,
body: ā€˜This is a test messageā€™,
isHtml: true
};
$cordovaEmailComposer.isAvailable().then(function() {
$cordovaEmailComposer.open(email).then(null, function () {
// user cancelled email
});
}, function () {
// not available
});
};

And it works.
Thanks everyone for the help and suggestion.
Happy Codding. :slight_smile:

1 Like