IceCoffeeAddictGerard
IceCoffeeAddictGerard

Reputation: 73

Ionic3 - Email Composer - Object(...) is not a function

For Ionic, I'm trying something with emails. So an user presses a button and goes to an email app to send an email with a set 'to', 'subject' and 'body'.

I followed the Ionic doc for EmailComposer : https://ionicframework.com/docs/native/email-composer

So I installed the plugin, followed the 'usage'.

 import { EmailComposer } from '@ionic-native/email-composer/ngx';

 constructor(private emailComposer: EmailComposer) { }

...


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

 let email = {
   to: '[email protected]',
   cc: '[email protected]',
   bcc: ['[email protected]', '[email protected]'],
   // attachments: [],
   subject: 'Cordova Icons',
   body: 'How are you? Nice greetings from Leipzig',
   isHtml: true
 }

 // Send a text message using default options
 this.emailComposer.open(email);

Only when I press the button. I get error :

 ERROR TypeError: Object(...) is not a function
 at EmailComposer.open (index.js:58)

I don't know the reason for this. I tried this in a fresh ionic3 project, but I still got the same error.

Upvotes: 3

Views: 1118

Answers (2)

The problem is you are telling the function what to do but aren't calling the function:

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

You have to name the function and after it, tell it what to do:

sendEmail() {
    this.emailComposer.isAvailable().then((available: boolean) => {
      if (available) {
      }
    });

    let email = {
      to: 'email@domain',
      subject: '',
      body: '',
      isHtml: true
    };
    this.emailComposer.open(email);
}

Upvotes: 0

Sudarshana Dayananda
Sudarshana Dayananda

Reputation: 5265

EmailComposer from @ionic-native/email-composer/ngx is not supporting in Ionic 3. It is supporting in Ionic 4. You need to install EmailComposer from @ionic-native/email-composer which supports for Ionic 3. Install EmailComposer using below command.

npm install --save @ionic-native/email-composer@4

Upvotes: 0

Related Questions