2016-01-13 81 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 :( –

相关问题