所以我一直试图用离子发送电子邮件。我尝试了许多教程,例子,但除了这一个之外没有任何工作:https://blog.nraboy.com/2014/08/send-email-android-ios-ionicframework/。
我要离开这个教程。请参阅下面的答案。
答案 0 :(得分:3)
以下是我在app.js中使用它的方法:
.controller('EmailCtrl', function($cordovaEmailComposer, $scope) {
$cordovaEmailComposer.isAvailable().then(function() {
// is available
alert("available");
}, function () {
// not available
alert("not available");
});
$scope.sendEmail = function(){
var email = {
to: 'teste@example.com',
cc: 'teste@example.com',
bcc: ['john@doe.com', 'jane@doe.com'],
attachments: [
'file://img/logo.png',
'res://icon.png',
'base64:icon.png//iVBORw0KGgoAAAANSUhEUg...',
'file://README.pdf'
],
subject: 'Mail subject',
body: 'How are you? Nice greetings from Leipzig',
isHtml: true
};
$cordovaEmailComposer.open(email).then(null, function () {
// user cancelled email
});
}
});
在我的index.html:
<button ng-click="sendEmail()" class="button button-icon icon ion-email">
Send mail
</button>
答案 1 :(得分:2)
cordova plugin add https://github.com/jcjee/email-composer.git
,link for repo ionic build android
现在准备AngularJS控制器:
angular.module('myApp').controller('WhatToDoController', function ($scope, $state) {
var whatToDo = this;
/**
* Sends an email using Email composer with attachments plugin and using
* parameter email.
*
* @param email
*/
whatToDo.sendEmail = function (email) {
if (window.plugins && window.plugins.emailComposer) { //check if plugin exists
window.plugins.emailComposer.showEmailComposerWithCallback(function (result) {
//console.log("Email sent successfully");
},
null, // Subject
null, // Body
[email], // To (Email to send)
null, // CC
null, // BCC
false, // isHTML
null, // Attachments
null); // Attachment Data
}
}
});
现在,在您的html视图中,您可以使用方法sendEmail(email)
:
<p>
Send an email to <a href="#" ng-click="whatToDo.sendEmail('example@email.com')">example@email.com</a>
</p>
尝试在实际的智能手机上使用它,因为在模拟器中如果您没有配置的电子邮件应用程序,它将无法正常工作。
如果您遇到问题或尝试某事:https://www.youtube.com/watch?v=kFfNTdJXVok或https://blog.nraboy.com/2014/08/send-email-android-ios-ionicframework