Reputation: 63
I am following this official documentation of ngCordova to send an Email eMail composer plugin with ngCordova.
the angularJs controller is :
module.controller('ThisCtrl', function($cordovaEmailComposer) {
$cordovaEmailComposer.isAvailable().then(function() {
// is available
}, function () {
// not available
});
var email = {
to: '[email protected]',
cc: '[email protected]',
bcc: ['[email protected]', '[email protected]'],
attachments: [
'file://img/logo.png',
'res://icon.png',
'base64:icon.png//iVBORw0KGgoAAAANSUhEUg...',
'file://README.pdf'
],
subject: 'Cordova Icons',
body: 'How are you? Nice greetings from Leipzig',
isHtml: true
};
$cordovaEmailComposer.open(email).then(null, function () {
// user cancelled email
});
});
How to call this from html page ? I want to when press a button, this code be called but there is no full example in their official web page
Upvotes: 0
Views: 475
Reputation: 4792
Yes right there is not full doc. please try nraboy blog. very nice article.
https://www.thepolyglotdeveloper.com/2014/08/send-email-android-ios-ionicframework/
Upvotes: 0
Reputation: 81
I take that you probably have found an answer since then but I had the same problem than you so I just tried a few things and this works for me:
<html>
<head>
<script>
var app = angular.module('propertyDeal', ['ngCordova']);
app.controller('ThisCtrl', function($scope, $cordovaEmailComposer) {
$scope.email = function() {
document.addEventListener("deviceready", function () {
$cordovaEmailComposer.isAvailable().then(function() {
alert("email available");
}, function () {
alert = ("email not available");
});
var email = {
to: '[email protected]',
cc: '[email protected]',
bcc: ['[email protected]', '[email protected]'],
attachments: [
'file://img/logo.png',
'res://icon.png',
'base64:icon.png//iVBORw0KGgoAAAANSUhEUg...',
'file://README.pdf'
],
subject: 'Cordova Icons',
body: 'How are you? Nice greetings from Leipzig',
isHtml: true
};
$cordovaEmailComposer.open(email).then(null, function () {
alert("email not sent");
});
}, false);
}
});
</script>
</head>
<body>
<div ng-controller="ThisCtrl">
<button class="button" ng-click="email()">Send an email</button>
</div>
<script type="text/javascript" src="components/ngCordova/ng-cordova.min.js"></script>
<script type="text/javascript" src="cordova.js"></script>
</body>
</html>
not quite sure it's the right way of doing it but it works...
Upvotes: 0