A bunch of email composition plugins for Cordova 3.x.x
by Sebastián Katzer (github.com/katzer)
-
iOS
See MFMailComposeViewController Class Reference for detailed informations and screenshots. -
Android
-
WP8
See How to use the email compose task for Windows Phone for detailed informations.
Through the Command-line Interface:
cordova plugin add https://github.com/katzer/cordova-plugin-email-composer.git
Through the Command-line Interface:
cordova plugin rm de.appplant.cordova.plugin.email-composer
Add the following xml to your config.xml to always use the latest version of this plugin:
<gap:plugin name="de.appplant.cordova.plugin.email-composer" />
or to use this exact version:
<gap:plugin name="de.appplant.cordova.plugin.email-composer" version="0.7.0" />
More informations can be found here.
- [enhancement:] Attachments are added with their real name.
- [bugfix:] Only the last attachment was added to the email composer on android.
- Release under the Apache 2.0 license.
- [change:] Removed the
callback
property from theopen
interface. - [change:] Renamed the properties
recipients
,ccRecipients
,bccRecipients
. - [bugfix:] Plugin under WP8 throws an error, if recipients were given as arrays.
- [enhancement:]
open
does not block the ui thread on iOS & Android anymore.
- Added WP8 support
- [deprecated:] The
callback
property will be removed with v0.7.0.
- [feature:] Added alias
openDraft
to theopen
interface.
- [bugfix]: On Android, the
isServiceAvailable()
interface has returned string values instead of boolean values. - [bugfix]: Sometimes the device said that no email app is available because of the missing mime type.
- Added Android support
Based on the EmailComposerWithAttachments Android plugin made by guidosabatini
- [bugfix]: Email was not send in HTML format, if the
isHtml
flag was set. - [bugfix]:
email.open()
without a parameter throw an error.
- Added iOS support
Based on the EmailComposer(WithAttachments) iOS plugin made by Randy McMillan and guidosabatini
The plugin creates the object window.plugin.email
with two methods:
Email service is only available on devices capable which are able to send emails. You can use this function to hide email functionality from users who will be unable to use it.
Function takes a callback function, passed to which is a boolean property. Optionally the callback scope can be assigned as a second parameter.
Android: Service is not available if no email accout is added on the device.
/*
* Find out if the sending of emails is available. Use this for showing/hiding email buttons.
*/
window.plugin.email.isServiceAvailable(
function (isAvailable) {
alert(isAvailable ? 'Service is available' : 'Service NOT available');
}
);
You can use this function to show the email view pre-filled with all kind of properties (see example below).
The function takes a hash where each property is optional. If a callback function is given, it will be called with a result code about the user action.
iOS: You can attach only PDF and images (the latter will be converted in PNG format).
/*
* Opens an email draft pre-filled with the passed properties.
*/
window.plugin.email.open({
to: Array, // contains all the email addresses for TO field
cc: Array, // contains all the email addresses for CC field
bcc: Array, // contains all the email addresses for BCC field
attachments: Array, // contains all full paths to the files you want to attach
subject: String, // represents the subject of the email
body: String, // represents the email body (could be HTML code, in this case set isHtml to true)
isHtml: Boolean, // indicats if the body is HTML or plain text
});
/*
* Opens a blank email draft.
*/
window.plugin.email.open();
window.plugin.email.open({
to: ['[email protected]'],
cc: ['[email protected]'],
bcc: ['[email protected]', '[email protected]'],
subject: 'Hello World!',
body: '<h3>TEST</h3><h2>TEST</h2><h1>TEST</h1>',
isHtml: true
});
An configured email account is required to send emails.
WP8: If an email account is not set up on the phone, the application prompts the user to set up an account.
Adding attachments and HTML formatted body are not supported.
Along with Cordova 3.2 and Windows Phone 8 the version.bat
script has to be renamed to version
.
On Mac or Linux
mv platforms/wp8/cordova/version.bat platforms/wp8/cordova/version
On Windows
ren platforms\wp8\cordova\version.bat platforms\wp8\cordova\version
The error indicates, that the MessageUI.framework
is not linked to your project. The framework is linked automatically when the plugin was installed, but may removed later.
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_MFMailComposeViewController", referenced from:
objc-class-ref in APPEmailComposer.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
This software is released under the Apache 2.0 License.