Ok, SendGrid was bouncing my emails due to a previous error (mailbox full). This is now fixed, and I am receiving the text part of my emails. The api_key_proxy also seems to be working when called from the app.
There is, however no attachment with the email, but here are no console errors from the fileUploadHelper
fileUploadHelper:
pre/**
- uploads a biary file (base64) using browserapi
*/
function uploadBinaryHelper(datasource, imageBase64Data, name, type) {
if (imageBase64Data) {
// strip header
var byteCharacters = atob(imageBase64Data.substring(imageBase64Data.indexOf(',') + 1));
var byteNumbers = new Array(byteCharacters.length);
for (var i = 0; i < byteCharacters.length; i++) {
byteNumbers = byteCharacters.charCodeAt(i);
}
var byteArray = new Uint8Array(byteNumbers);
//imageType is always pdf
var imageType = 'pdf';
var imageName = name ||new Date().getTime();
var blob = new Blob([byteArray.buffer], {
type: 'application/pdf'
});
Code: Select all
var formData = new FormData();
var sendGridFileName = imageName + '.' + imageType;
formData.append('files[' + sendGridFileName + ']', blob);
if (datasource && datasource.service) {
try {
datasource.execute({
'allowDataModification' : false,
'processData' : false,
'contentType' : false,
'body' : formData,
'cache' : false
});
} catch (exception) {
console.log(exception.name + ' ' + exception.message);
hideSpinner();
}
} else {
console.warn('This data source is not correct');
}
} else {
console.warn('image data is empty or has a wrong format.');
}
}/pre
email button click event:
pre// Build up Invoice from data
//trader address
var traderLogoUrl = Apperyio.storage.currentFullInvoice.get("$['traderlogourl']");
var traderTradingName = Apperyio.storage.currentFullInvoice.get("$['tradertradingname']");
var traderStreetAddress = Apperyio.storage.currentFullInvoice.get("$['traderaddress1']");
var traderTown = Apperyio.storage.currentFullInvoice.get("$['tradertown']");
var traderCounty = Apperyio.storage.currentFullInvoice.get("$['tradercounty']");
var traderPostcode = Apperyio.storage.currentFullInvoice.get("$['traderpostcode']");
var clientName = Apperyio.storage.currentFullInvoice.get("$['clientfirstname']") + " " + Apperyio.storage.currentFullInvoice.get("$['clientlastname']");
var clientStreetAddress = Apperyio.storage.currentFullInvoice.get("$['clientaddress1']");
var clientTown = Apperyio.storage.currentFullInvoice.get("$['clienttown']");
var clientCounty = Apperyio.storage.currentFullInvoice.get("$['clientcounty']");
var clientPostcode = Apperyio.storage.currentFullInvoice.get("$['clientpostcode']");
var traderVatNumber = Apperyio.storage.currentFullInvoice.get("$['tradervatnumber']");
var productDescription = Apperyio.storage.currentFullInvoice.get("$['productdescription']");
var productPrice = Apperyio.storage.currentFullInvoice.get("$['productprice']");
var invoiceAmount = Apperyio.storage.currentFullInvoice.get("$['invoiceamount']");
var invoiceVatAmount = Apperyio.storage.currentFullInvoice.get("$['invoicevatamount']");
var InvoicePDFCreator = {
createPDF: function(filename) {
//create document object
var doc = new jsPDF();
console.log('executed doc=newjsPDF();');
Code: Select all
//title
doc.setFontSize(22);
doc.textEx('Invoice', 105, 20, 'center');
console.log('executed doc.textEx("invoice",105,20,"center");');
//logo
var imgDATA = traderLogoUrl;
doc.addImage(imgDATA, 'JPEG', 150, 5, 50, 40);
//trader address box
doc.rect(20, 50, 80, 50);
doc.setFontSize(14);
doc.textEx(traderTradingName, 25, 55);
doc.textEx(traderStreetAddress, 25, 62);
doc.textEx(traderTown, 25, 69);
doc.textEx(traderCounty, 25, 76);
doc.textEx(traderPostcode, 25, 83);
// customer address box
doc.rect(110, 50, 80, 50);
doc.setFontSize(14);
doc.textEx(clientName, 115, 55);
doc.textEx(clientStreetAddress, 115, 62);
doc.textEx(clientTown, 115, 69);
doc.textEx(clientCounty, 115, 76);
doc.textEx(clientPostcode, 115, 83);
// Invoice Detail
doc.setFontSize(14);
doc.rect(20, 110, 170, 100);
doc.rect(160, 110, 30, 110);
doc.textEx(productDescription, 25, 130);
doc.textEx(invoiceAmount.formatMoney(), 187, 130, 'right');
doc.textEx('VAT', 155, 200, 'right');
doc.textEx(invoiceVatAmount.formatMoney(), 187, 200, 'right');
doc.textEx('Total', 155, 213, 'right');
doc.textEx((invoiceAmount + invoiceVatAmount).formatMoney(), 187, 213, 'right');
//VAT Number
doc.setFontSize(10);
doc.textEx('VAT Registration Number: ' + traderVatNumber, 105, 280, 'center');
var uristring = doc.output('datauristring');
// the email plugin uses a non-standard URI format, so the filename can be specified.
if (filename) {
var uristringparts = uristring.split(',');
uristringparts[0] = "base64:" + escape(filename) + "//";
var moddeduristring = uristringparts.join("");
return moddeduristring;
} else {
return uristring;
}
},
displayPDF: function(uristring) {
var ref = window.open(uristring, "_blank", "EnableViewPortScale=yes,location=no,disallowoverscroll=yes,allowInlineMediaPlayback=yes,toolbarposition=top,transitionstyle=fliphorizontal");
return ref;
},
createAndDisplayPDF: function(filename) {
var uristring = this.createPDF(filename);
var ref = this.displayPDF(uristring);
return ref;
},
emailPDF: function(datauri) {
uploadBinaryHelper(emailService, datauri);
},
createAndEmailPDF: function(filename) {
var uristring = this.createPDF(filename);
this.emailPDF(uristring);
}
};
console.log('InvoicePDFCreator ',InvoicePDFCreator);
InvoicePDFCreator.createAndEmailPDF();
/pre
I know that uploadBinaryHelper() is being called because the email is sent. For some reason, there is no attachment.