我正在按照ngCordova的此官方文档发送电子邮件通过ngCordova向composer插件发送电子邮件。
angularJs控制器是:
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
});
});
如何从html页面调用此代码?我想在按下按钮时调用此代码,但在其官方网页上没有完整的示例
我认为您从那以后可能已经找到答案了,但是我遇到了与您相同的问题,所以我只尝试了一些方法,这对我有用:
<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>
不太确定这是正确的方法,但是它可以工作...
是的,没有完整的文档。请尝试nraboy博客。非常好的文章。
https://www.thepolyglotdeveloper.com/2014/08/send-email-android-ios-ionicframework/