简体   繁体   English

如何使用angular js和ionic框架发送电子邮件

[英]How to send email using angular js and ionic framework

I tried sending email by referring various links but in vain.I just want to send email and below is my code for sending email. 我试着参照各个环节,但在vain.I发送电子邮件只是想发送电子邮件和下面是我用于发送电子邮件的代码。 Please suggest the changes . 请提出更改建议。
Thanks in advance :) 提前致谢 :)
index.html index.html

<!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 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: 'siddhesh.kalgaonkar@ves.ac.in',
      cc: 'monish.gupte@mservices.in',
      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");
});  

When i test in browser it shows below error : 当我在浏览器中测试时,显示以下错误:

TypeError: Cannot read property 'plugins' of undefined  

and when i test it on mobile phone it doesnt work on it as well. 当我在手机上对其进行测试时,它也无法正常运行。

For email, you will have to install Cordova Email Plugin . 对于电子邮件,您将必须安装Cordova电子邮件插件 The plugin provides access to the standard interface that manages the editing and sending an email message. 该插件提供对管理编辑和发送电子邮件的标准界面的访问。 Install using CLI 使用CLI安装

cordova plugin add https://github.com/katzer/cordova-plugin-email-composer.git cordova插件添加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.');
        }
      }
    );
};

I have used like this after installing Cordova Email Plugin in my project.. hope it may help... 在我的项目中安装Cordova电子邮件插件后 ,我就这样使用过。

$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
              ["ameerhamza810@gmail.com"],    // To
              null,                    // CC
              null,                    // BCC
              false,                   // isHTML
              null,                    // Attachments
              null);                   // Attachment Data
          }
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM