How to send email using ionic infrastructure using your own email application

So, I'm stuck trying to send an ionic email. I tried a lot of tutorials, examples, but nothing worked except this one: https://blog.nraboy.com/2014/08/send-email-android-ios-ionicframework/ .

I am leaving this tutorial here. Below is the answer.

+4
source share
2 answers

Very simple

  • Go to the root directory of the application
  • Install Email Composer plugins investments : cordova plugin add https://github.com/jcjee/email-composer.git, link to repo
  • , , Android: ionic build android
  • 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
      }
    
    }
    });
    
  • html sendEmail(email):

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

  • , , , .

- : https://www.youtube.com/watch?v=kFfNTdJXVok https://blog.nraboy.com/2014/08/send-email-android-ios-ionicframework

+1

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: 'teste@example.com',
     cc: 'teste@example.com',
     bcc: ['john@doe.com', 'jane@doe.com'],
     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>
+2

Source: https://habr.com/ru/post/1609682/


All Articles