因此,我試圖用離子發送電子郵件卡住了。我嘗試了很多教程,但是沒有任何工作,除了這個:https://blog.nraboy.com/2014/08/send-email-android-ios-ionicframework/。如何使用本機電子郵件應用程序發送帶離子框架的電子郵件
我在這裏離開本教程。請參閱下面的答案。
因此,我試圖用離子發送電子郵件卡住了。我嘗試了很多教程,但是沒有任何工作,除了這個:https://blog.nraboy.com/2014/08/send-email-android-ios-ionicframework/。如何使用本機電子郵件應用程序發送帶離子框架的電子郵件
我在這裏離開本教程。請參閱下面的答案。
cordova plugin add https://github.com/jcjee/email-composer.git
,link for repo例如用於爲Android所需的平臺ionic build android
現在準備好您的AngularJS控制器:
在模擬器<p>
Send an email to <a href="#" ng-click="whatToDo.sendEmail('[email protected]')">[email protected]</a>
</p>
嘗試使用這個在實際的智能手機,因爲如果您有:
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)
沒有配置的電子郵件應用程序將無法正常工作
如果您遇到問題或一些嘗試:https://www.youtube.com/watch?v=kFfNTdJXVok或https://blog.nraboy.com/2014/08/send-email-android-ios-ionicframework
這是我如何使用它在我的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: '[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: '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>
你能告訴你使用了哪個插件用於上述答案嗎? –
https://github.com/katzer/cordova-plugin-email-composer –
我跟着博客,庫中的函數觸發回調從不執行。我似乎無法找到問題。控制檯上沒有錯誤:/ – AhsanAyaz