如何使用本机电子邮件应用程序使用 ionic 框架发送电子邮件

Com*_*ode 5 ionic-framework ionic-view

所以我一直在尝试用 ionic 发送电子邮件。我尝试了很多教程,示例,但除了这个之外没有任何效果:https : //www.thepolyglotdeveloper.com/2014/08/send-email-android-ios-ionicframework/

我要把这个教程放在这里。请参阅下面的答案。

Com*_*ode 3

好简单

  1. 转到您的应用程序根目录
  2. 安装带有附件的电子邮件编辑器插件类型:cordova plugin add https://github.com/jcjee/email-composer.git存储库链接
  3. 为您所需的平台重新构建项目,例如 android:ionic build android
  4. 现在准备你的 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
      }
    
    }
    });
    
    Run Code Online (Sandbox Code Playgroud)
  5. 现在在您的 html 视图中您可以使用该方法sendEmail(email)

    <p>
    Send an email to <a href="#" ng-click="whatToDo.sendEmail('example@email.com')">example@email.com</a>
    </p>
    
    Run Code Online (Sandbox Code Playgroud)

  6. 尝试在实际的智能手机上使用它,因为在模拟器中,如果您没有配置电子邮件应用程序,它将无法正常工作。

如果您遇到困难或尝试:https://www.youtube.com/watch?v = kFfNTdJXVok 或https://blog.nraboy.com/2014/08/send-email-android-ios-ionicframework