$cordovaEmailComposer can not send mail


#1

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


#2

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?


#3

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


#4

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


#5

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:


#6

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


#7

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


#8

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.


#9

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


#10

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.


#11

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: