For those of you trying to send a camera picture, use the following code in the SendMailCustomerImp Javascript instead of the pieces of code in http://blog.bismallion.com/sending-em...:
code start------------------------------------------------------------------------------
Appery.SendMailCustom = Appery.createClass(null, {
init : function(requestOptions) {
this.__requestOptions = $.extend({}, requestOptions);
},
process : function(settings) {
settings.beforeSend(settings);
if (this.requestOptions.echo) {
settings.success(this.requestOptions.echo);
} else {
//console.log('Default implementation is used. Please define your own.');
//set up local variable called photo_buffer. Update it after photo taken
//put reference to your page fields in var msg that you want to be in body of email
var msg = 'here is my pic';
//add email addresses, subject, and your sendgrid userid and pwd
var fields = {
"api_user": "your user id",
"api_key": "your pwd",
"to": "to email address",
"toname": "name of To person",
"subject": "test",
"html": msg,
"from": "from email address"
};
var formData = new FormData();
for (var ii in fields) {
formData.append(ii, fields[ii]);
}
var f =localStorage.getItem("photo_buffer");
// Read file content first
//call function to convert base64 to jpg
var blob =dataURItoBlob(f);
var fileName = 'mypic.jpg';
// Read file name first
formData.append("files[" + fileName + "]", blob);
var request = new XMLHttpRequest();
request.withCredentials = true;
request.open("POST", "https://api.sendgrid.com/api/mail.sen...");
request.setRequestHeader("Access-Control-Allow-Origin", "*");
request.setRequestHeader("X-Requested-With", "XMLHttpRequest");
request.send(formData);
request.onreadystatechange = function() {
if (request.readyState == 4 && request.status == 200) {
console.log('E-mail sent successfully');
Apperyio('Message').text('E-mail sent');
setTimeout(function(){Apperyio('status_label').text('Ready');},2000);
}
};
Code: Select all
settings.success({});
}
settings.complete('success');
alert ('Email sent!');