Email composer don't work Ionic

Hello, I have a small problem with the email composer.
I have this code:

import { Component, ViewChild } from '@angular/core';
import { NavController} from 'ionic-angular';
import { SignaturePad } from 'angular2-signaturepad/signature-pad';
import { EmailComposer } from '@ionic-native/email-composer';
import { HomePage } from '../home/home';

@Component({
  selector: 'page-envoie',
  templateUrl: 'envoie.html',
  providers: [SignaturePad, EmailComposer]
})
export class EnvoiePage {

  @ViewChild(SignaturePad) public signaturePad: SignaturePad;

  constructor(public navCtrl: NavController, private emailComposer: EmailComposer){

  }

  public signatureImage : string;
  public signaturePadOptions: Object = {
        'minWidth': 2,
        'canvasWidth': 340,
        'canvasHeight': 200 };

   drawComplete() {

    this.signatureImage = this.signaturePad.toDataURL();

    let email = {
      to: 'erika@mustermann.de',
      //cc: 'erika@mustermann.de',
      //bcc: ['john@doe.com', 'jane@doe.com'],
      attachments: [
        this.signatureImage
      ],
      subject: 'Test facturation',
      body: 'Trql frr?',
      isHtml: true
    };
    
    this.emailComposer.isAvailable().then((available: boolean) =>{
    if(available) {
      this.emailComposer.open(email);

      this.navCtrl.push(HomePage);
    }
    });
  
  }

  drawClear() {
    this.signaturePad.clear();
  }

}

When I press the button, nothing happen I don’t know why. I followed a tuto

How are you testing?
How are you building or running your app?

I’m testing on my iPhone with ionic view

Hmm, Email Composer is actually one of the supported plugins of Ionic View: https://docs.ionic.io/tools/view/#supported-plugins

Did you https://ionicframework.com/docs/native/#Add_Plugins_to_Your_App_Module?

Is available false?
I would test it with a new blank project, without signature-pad.

Not likely relevant, but it’s fairly rare that one would actually want to declare providers on a per-component basis instead of just in the app module.

1 Like

Available is false

That at least means everything is working as it should.

Is it true with different devices? On a different platform? Test with ionic cordova run etc, not Ionic View.
Are you sure the platform is ready? Wrap it inside a check to make sure.

Signature pad don’t appear when I use a simulator, only in ionic serve and on ionic view

Someone can help me? Is available is not true

Please go through my posts and answer each question I asked you.

It’s false on both iOS or Android, in ionic view or ionic run. The platform is ready how to know that? I don’t know how to wrap it in a check, i’m new to ionic

Google “ionic platform ready”. First result. Search for “platform ready” in that page.

I used this this.plt.ready().then((readySource) => {console.log('Platform ready from', readySource);}); and nothing is showed in the console

Did you also import plt: Platform in the constructor and import the class so DI works?

Yes I did it but nothing happens

That is not really possible. See app.component.ts for an example on how to use the ready check properly.

It works because in my app.component.ts,

initializeApp() {
    this.platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      this.statusBar.styleDefault();
      this.splashScreen.hide();
    });
  }

this code is executed

Ok I don’t know why but my emailComposer.isAvailable() wasn’t true, I tried without the is available and everything works. I can send email, etc

But I have a question, my attachements don’t work, do you know why?

1 Like

No. Please open a new topic about that and include all relevant information.

Please, take a look at the Ionic Native Email Composer source code. It doesn’t send the “isAvailable” parameter. Instead it will reject the the promise when the variable is false.

3 Likes