How to send an email with ionic framework using the native email application?(android and ios)

Hi, I am going to teach about how to send an email with ionic framework using the native email application in ionic 3 and Angular 4.


First, we want to install ionic Cordova plugin in CLI.
                  $ ionic cordova plugin add cordova-plugin-email-composer
                  $ npm install --save @ionic-native/email-composer
Home.html
          <ion-header>
              <ion-navbar>
                  <ion-title>
                       EMAIL
                  </ion-title>
               </ion-navbar>
           </ion-header>
          <ion-content padding fullscreen="true">
               <div text-center style="margin-top: 5cm">
                      <button ion-button (tap)="send()">Send-Email</button>
                 </div>
          </ion-content>                                    
app.module.ts
     import { EmailComposer } from '@ionic-native/email-composer';
     providers: [
             .....            
           EmailComposer,
             .....
              ]     
Home.ts
      import { Component } from '@angular/core';
      import {NavController, ToastController} from 'ionic-angular';
      import { EmailComposer } from '@ionic-native/email-composer';
      @Component({
           selector: 'page-home',
           templateUrl: 'home.html'                })
      export class HomePage {    
      constructor(private emailComposer: EmailComposer) {

       }

      send(){
      this.emailComposer.isAvailable().then((available: boolean) =>{
      if(available) {
        //Now we know we can send      }
      });

      let email = {
      to: 'example@gmail.com',
      subject: 'Cordova Icons',
      body: 'How are you? Nice greetings from Leipzig',
      isHtml: true       };

How to send an email with ionic framework using the native email application?(android and ios) How to send an email with ionic framework using the native email application?(android and ios) Reviewed by Sudhan on October 10, 2017 Rating: 5

7 comments:

  1. Run time error. Its says cordova_not_available

    ReplyDelete
    Replies
    1. First you want to add plugin

      https://ionicframework.com/docs/native/email-composer/

      Delete
  2. not working! cordova_not_available. was installed but not working, please help me?

    ReplyDelete
    Replies
    1. did you find a solution?? i have the same problem

      Delete
  3. Hey thanks for the Solution , as this is by cordova plugin you need to run it on device , it will not be working in browser

    ReplyDelete
  4. hi, thnks for the tutorial. im kind of new on ionic and i dont understend where i link the "email" sentence on "let email = {" with the form. sorry if my question is to obvious

    ReplyDelete
  5. Cannot read property 'split' of undefined this error comming

    ReplyDelete

LightBlog
Powered by Blogger.