Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to send email with ionic framework using the native email app

So I was stuck trying to send email with ionic. I tried many tutorials, examples but nothing worked except this one: https://www.thepolyglotdeveloper.com/2014/08/send-email-android-ios-ionicframework/.

I'm leaving this tutorial here. Please see below for the answer.

like image 886
CommonSenseCode Avatar asked Sep 30 '15 18:09

CommonSenseCode


1 Answers

Here is how I use it in my 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
  });
 }
});

And here in my index.html:

<button ng-click="sendEmail()" class="button button-icon icon ion-email">
   Send mail
</button>
like image 191
bandojulio Avatar answered Sep 28 '22 03:09

bandojulio