2015-09-30 106 views

回答

1

非常容易

  1. 轉到您的應用程序根目錄
  2. 安裝電子郵件作曲家帶附件插件類型:cordova plugin add https://github.com/jcjee/email-composer.gitlink for repo例如用於爲Android所需的平臺
  3. 重新構建項目: ionic build android
  4. 現在準備好您的AngularJS控制器:

    在模擬器

    <p> 
    Send an email to <a href="#" ng-click="whatToDo.sendEmail('[email protected]')">[email protected]</a> 
    </p> 
    

  5. 嘗試使用這個在實際的智能手機,因爲如果您有:

    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 
        } 
    
    } 
    }); 
    
  6. 現在在你的HTML視圖中可以使用的方法sendEmail(email)沒有配置的電子郵件應用程序將無法正常工作

如果您遇到問題或一些嘗試:https://www.youtube.com/watch?v=kFfNTdJXVokhttps://blog.nraboy.com/2014/08/send-email-android-ios-ionicframework

+0

我跟着博客,庫中的函數觸發回調從不執行。我似乎無法找到問題。控制檯上沒有錯誤:/ – AhsanAyaz

2

這是我如何使用它在我的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> 
+0

你能告訴你使用了哪個插件用於上述答案嗎? –

+0

https://github.com/katzer/cordova-plugin-email-composer –

相關問題