I am trying to use the EmailComposer plugin:
I installed it with:
cordova plugin add https://github.com/katzer/cordova-plugin-email-composer.git
But when I try to use it:
var ec = new EmailComposer();
I get ‘Uncaught ReferenceError: EmailComposer is not defined’
What am I missing here?
Thanks
2 Likes
I believe you need to run “cordova build” to actually generate the plugin code in the relevant platform directory.
I already did that but I still get the same error
Ah EmailComposer isn’t what you want to reference - use window.plugin.email. Example:
window.plugin.email.open({
to: ['max.mustermann@appplant.de'],
cc: ['erika.mustermann@appplant.de'],
bcc: ['john.doe@appplant.com', 'jane.doe@appplant.com'],
subject: 'Greetings',
body: 'How are you? Nice greetings from Leipzig'
});
1 Like
That works. Thanks a lot. It still puzzles me why EmailComposer is not recognized as the email_composer.js that exists under plugins/de.applat.xxx/www/ directory defines that.
That’s because in www/cordova_plugins.js it’s set to be inserted into the window object as plugin.email (see the clobbers properties in that js file). Notice in email_composer.js that EmailComposer is only defined/declared in the scope of a cordova.define & not the global window scope.
Anyone know how to use the callback function about emailcomposer?
The open
method supports an additional callback to get informed when the view has been dismissed.
window.plugin.email.open(
{
to: Array, // email addresses for TO field
cc: Array, // email addresses for CC field
bcc: Array, // email addresses for BCC field
attachments: Array, // paths to the files you want to attach or base64 encoded data streams
subject: String, // subject of the email
body: String, // email body (could be HTML code, in this case set isHtml to true)
isHtml: Boolean, // indicats if the body is HTML or plain text
}, function () {
// Callback
console.log('email view dismissed');
}, scope);
I tried it but it not work!
This is my code :
window.plugin.email.open({
//to do get email contact
subject: “Display at image”,
to:[$scope.sendEmailname],
attachments:[$scope.picData]}, function () {
console.log(‘email view dismissed’);
}, $scope);
Try this:
window.plugin.email.open(
{
subject: "Display at image",
to:[$scope.sendEmailname],
attachments:[$scope.picData]
},
function () {
console.log('email view dismissed');
},
this
);
Tried, same result…
window.plugin.email.open({
//to do get email contact
subject: “Display at image”,
to:[$scope.sendEmailname’],
attachments:[$scope.picData]}, function () {
console.log(‘email view dismissed’);
}, this);
It does work for me.
- Did you install the plugin?
- Does the compose window even open?
- Do you wait until Cordova is ready (
$ionicPlatform.ready
)?
- Did you add
$ionicPlatform
to your controller?
- Maybe there’s a problem with your variables
$scope.sendEmailname
and $scope.picData`
Try something single which works a 100 %:
// Wait until Cordova is ready
$ionicPlatform.ready(function() {
window.plugin.email.open(
{
subject: 'Display at image'
},
function () {
alert('email view dismissed');
},
this
);
});
Hi
I have also been facing the problems related to callback.I have been using the following lines of code to call the email composer in my windows phone 8 app
window.plugin.email.open({
to: '',
cc: '',
bcc: '',
subject: emailShare.message,
body: emailShare.description
},callback,this);
the callback function gets fired the moment when the above function is called.What i want is i want to fire the callback method when the mail has been sent.
What am i missing please help
Hi to all. I struggle to make it work so far.
I am using phonegap developer app to test it.
For testing purposes i do this
window.plugin.email.open();
to show an empty email composer but the app doesn’t do anything.
I an using the latest version (0.8.2dev).
my installation process is this
cordova plugin add de.appplant.cordova.plugin.email-composer@0.8.2
and then i put the snipet from above in my controller.
Do i need to place something in the confiig.xml or something??
Thank you
Did you try to see whether email service is available?
window.plugin.email.isServiceAvailable(
function (isAvailable) {
console.log("it is available);
}
);
Also, I would try to open the email composer with some options:
window.plugin.email.open({
to: [$scope.to],
subject: $scope.subject,
body: $scope.body,
isHtml: true
});
I know I am not giving you pearls here but it’s worth a shot.
As the creator of the app says:
This interface does not provide a way for you to verify whether emails were actually sent.
reference: GitHub - katzer/cordova-plugin-email-composer: Edit and send email messages
If you try to simulate on chrome I think that not work fine,because not found plugin, Although I have the plugin installed and I have verified the path…