So I was stuck trying to send email with ionic. I tried many tutorials, examples but nothing worked except this one: https://www.thepolyglotdeveloper.com/2014/08/send-email-android-ios-ionicframework/.
I'm leaving this tutorial here. Please see below for the answer.
cordova plugin add https://github.com/jcjee/email-composer.git
, link for repoionic build android
Now prepare your AngularJS controller:
angular.module('myApp').controller('WhatToDoController', function ($scope, $state) {
var whatToDo = this;
/**
* Sends an email using Email composer with attachments plugin and using
* parameter email.
*
* @param email
*/
whatToDo.sendEmail = function (email) {
if (window.plugins && window.plugins.emailComposer) { //check if plugin exists
window.plugins.emailComposer.showEmailComposerWithCallback(function (result) {
//console.log("Email sent successfully");
},
null, // Subject
null, // Body
[email], // To (Email to send)
null, // CC
null, // BCC
false, // isHTML
null, // Attachments
null); // Attachment Data
}
}
});
Now in your html view you can use the method sendEmail(email)
:
<p>
Send an email to <a href="#" ng-click="whatToDo.sendEmail('[email protected]')">[email protected]</a>
</p>
Try to use this on an actual smartphone since in the emulator if you have no configured email app it won't work properly.
If you get stuck or something try: https://www.youtube.com/watch?v=kFfNTdJXVok or https://blog.nraboy.com/2014/08/send-email-android-ios-ionicframework