Email composer don't work Ionic


#1

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


#2

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


#3

I’m testing on my iPhone with ionic view


#4

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.


#5

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.


#6

Available is false


#7

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.


#8

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


#10

Someone can help me? Is available is not true


#11

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


#12

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


#13

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


#14

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


#15

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


#16

Yes I did it but nothing happens


#17

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


#18

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


#19

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?


#20

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


#21

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.