2016-01-13 65 views
0

我試過發送電子郵件通過參考各種鏈接,但徒勞。我只是想發送電子郵件,以下是我的代碼發送電子郵件。請建議更改。
感謝提前:)
的index.html如何使用角度js和離子框架發送電子郵件

<!DOCTYPE html> 
<html> 
    <head> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"> 
    <title></title> 

    <link href="lib/ionic/css/ionic.css" rel="stylesheet"> 
    <link href="css/style.css" rel="stylesheet"> 
    <script src="lib/ionic/js/ionic.bundle.js"></script> 
    <script src="lib/ionic/js/ng-cordova.min.js"></script> 
    <script src="js/cordova.js"></script> 
    <script src="js/app.js"></script> 
    </head> 
    <body ng-app="starter" ng-controller="ExampleController"> 

    <ion-pane> 
     <ion-content> 
     <div class="padding"> 
     <button class="button button-icon icon ion-email" ng-click="vesitEmail()"> 
      Send Email 
     </button> 
     </div> 
     </ion-content> 
    </ion-pane> 
    </body> 
</html> 

App.js

var example=angular.module('starter', ['ionic','ngCordova']) 
.run(function($ionicPlatform) { 
    $ionicPlatform.ready(function() { 
    if(window.cordova && window.cordova.plugins.Keyboard) { 
     cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); 
     cordova.plugins.Keyboard.disableScroll(true); 
    } 
    if(window.StatusBar) { 
     StatusBar.styleDefault(); 
    } 
    }); 
}); 
example.controller('ExampleController', function($scope,$cordovaEmailComposer) { 
    $cordovaEmailComposer.isAvailable().then(function() { 
    // is available 
    alert("available"); 
    }, function() { 
    // not available 
    alert("not available"); 
    }); 
    $scope.vesitEmail = function(){ 
    var email = { 
     to: '[email protected]', 
     cc: '[email protected]', 
     bcc: null, 
     attachments: null, 
     subject: 'Mail subject', 
     body: 'How are you? Nice greetings from Leipzig', 
     isHtml: true 
    }; 

    $cordovaEmailComposer.open(email).then(null, function() { 
     // user cancelled email 
    }); 
    } 
    window.alert("Message Sent"); 
}); 

,當我在瀏覽器中測試它顯示如下錯誤:

TypeError: Cannot read property 'plugins' of undefined 

當我在手機上測試它,它也不起作用。

+0

你能確認window.cordova和window.cordova.plugins可用嗎? – Matheno

+0

我該怎麼做? –

+0

以防萬一..!檢查'org.apache.cordova.statusbar'插件是否安裝..!因爲您使用'window.StatusBar'..!插件問題解決先生 –

回答

0

對於電子郵件,您將需要安裝Cordova Email Plugin。該插件提供對管理編輯和發送電子郵件的標準界面的訪問。安裝使用CLI

科爾多瓦插件添加https://github.com/katzer/cordova-plugin-email-composer.git

$scope.vesitEmail = function(){ 
    cordova.plugins.email.isAvailable(
     function (isAvailable) { 
     if(isAvailable){ 
      cordova.plugins.email.open({ 
      to:  [''], 
      cc:  [''], 
      bcc:  [''], 
      subject: '', 
      body: '' 
      });  
     }else{ 
      alert('Service is not available.'); 
     } 
     } 
    ); 
}; 
+0

我測試了移動@Ved先生的代碼,但沒有工作:( –

+0

在瀏覽器上的按鈕點擊它給出TypeError:無法讀取屬性'插件'的範圍內的undefined $ scope.vesitEmail –

+0

你安裝插件propperly ..?不檢查瀏覽器,測試phonegap生成應用 – Ved

0

我用這樣在我的項目安裝Cordova Email Plugin後..希望它可以幫助...

$scope.sendEmail = function() { 
      if (window.plugins && window.plugins.emailComposer) { 
      window.plugins.emailComposer.showEmailComposerWithCallback(function (result) { 
       alert(result); 
      }, 
       "Feedback Form", // Subject 
       $scope.emailText[0].body,      // Body 
       ["[email protected]"], // To 
       null,     // CC 
       null,     // BCC 
       false,     // isHTML 
       null,     // Attachments 
       null);     // Attachment Data 
      } 
     } 
+0

Doesnt工作。也在移動設備上進行測試。不會給出任何錯誤 –

+0

您是否正確安裝了插件? 定義任何正文文本代替$ scope.emailText [0] .body –

+0

是的,我已經正確安裝插件仍然不工作sir :( –

相關問題