Terry Gilliver
Posts: 0
Joined: Fri Apr 18, 2014 8:45 pm

Sendgrid

Ok Just set up a email service: Image

Image

Image

Image

Image

I set up api_key_proxy in a database containing my sendgrid api_key with 'bearer' preceding the api_key.

If I copy and paste this value into the test header Authorization field, I get {message:success} which suggests that api_key_proxy is not being picked up from the database. Also, even though i get a success message, the email is not sent.

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Sendgrid

SendGrid has a log that might show you the error - why the email is not delivered.

Terry Gilliver
Posts: 0
Joined: Fri Apr 18, 2014 8:45 pm

Sendgrid

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&#46;length; i++) {
    byteNumbers = byteCharacters&#46;charCodeAt(i);
    }
    var byteArray = new Uint8Array(byteNumbers);
    &#47;&#47;imageType is always pdf
    var imageType = 'pdf';
    var imageName = name ||new Date()&#46;getTime();
    var blob = new Blob([byteArray&#46;buffer], {
    type: 'application/pdf'
    });

    Code: Select all

     var formData = new FormData(); 
     var sendGridFileName = imageName + '&#46;' + imageType; 
     formData&#46;append('files[' + sendGridFileName + ']', blob); 
    
     if (datasource && datasource&#46;service) { 
         try { 
             datasource&#46;execute({ 
                 'allowDataModification' : false, 
                 'processData' : false, 
                 'contentType' : false, 
                 'body' : formData, 
                 'cache' : false 
             }); 
         } catch (exception) { 
             console&#46;log(exception&#46;name + ' ' + exception&#46;message); 
             hideSpinner(); 
         } 
     } else { 
         console&#46;warn('This data source is not correct'); 
     } 

} else {
console&#46;warn('image data is empty or has a wrong format&#46;');
}
}/pre

email button click event:

pre&#47;&#47; Build up Invoice from data

&#47;&#47;trader address
var traderLogoUrl = Apperyio&#46;storage&#46;currentFullInvoice&#46;get("$['traderlogourl']");
var traderTradingName = Apperyio&#46;storage&#46;currentFullInvoice&#46;get("$['tradertradingname']");
var traderStreetAddress = Apperyio&#46;storage&#46;currentFullInvoice&#46;get("$['traderaddress1']");
var traderTown = Apperyio&#46;storage&#46;currentFullInvoice&#46;get("$['tradertown']");
var traderCounty = Apperyio&#46;storage&#46;currentFullInvoice&#46;get("$['tradercounty']");
var traderPostcode = Apperyio&#46;storage&#46;currentFullInvoice&#46;get("$['traderpostcode']");

var clientName = Apperyio&#46;storage&#46;currentFullInvoice&#46;get("$['clientfirstname']") + " " + Apperyio&#46;storage&#46;currentFullInvoice&#46;get("$['clientlastname']");
var clientStreetAddress = Apperyio&#46;storage&#46;currentFullInvoice&#46;get("$['clientaddress1']");
var clientTown = Apperyio&#46;storage&#46;currentFullInvoice&#46;get("$['clienttown']");
var clientCounty = Apperyio&#46;storage&#46;currentFullInvoice&#46;get("$['clientcounty']");
var clientPostcode = Apperyio&#46;storage&#46;currentFullInvoice&#46;get("$['clientpostcode']");

var traderVatNumber = Apperyio&#46;storage&#46;currentFullInvoice&#46;get("$['tradervatnumber']");

var productDescription = Apperyio&#46;storage&#46;currentFullInvoice&#46;get("$['productdescription']");
var productPrice = Apperyio&#46;storage&#46;currentFullInvoice&#46;get("$['productprice']");
var invoiceAmount = Apperyio&#46;storage&#46;currentFullInvoice&#46;get("$['invoiceamount']");
var invoiceVatAmount = Apperyio&#46;storage&#46;currentFullInvoice&#46;get("$['invoicevatamount']");

var InvoicePDFCreator = {
createPDF: function(filename) {
&#47;&#47;create document object
var doc = new jsPDF();
console&#46;log('executed doc=newjsPDF();');

Code: Select all

     &#47;&#47;title 
     doc&#46;setFontSize(22); 
     doc&#46;textEx('Invoice', 105, 20, 'center'); 
     console&#46;log('executed doc&#46;textEx("invoice",105,20,"center");'); 

     &#47;&#47;logo 
     var imgDATA = traderLogoUrl; 

     doc&#46;addImage(imgDATA, 'JPEG', 150, 5, 50, 40); 

     &#47;&#47;trader address box 
     doc&#46;rect(20, 50, 80, 50); 
     doc&#46;setFontSize(14); 
     doc&#46;textEx(traderTradingName, 25, 55); 
     doc&#46;textEx(traderStreetAddress, 25, 62); 
     doc&#46;textEx(traderTown, 25, 69); 
     doc&#46;textEx(traderCounty, 25, 76); 
     doc&#46;textEx(traderPostcode, 25, 83); 

     &#47;&#47; customer address box 
     doc&#46;rect(110, 50, 80, 50); 
     doc&#46;setFontSize(14); 
     doc&#46;textEx(clientName, 115, 55); 
     doc&#46;textEx(clientStreetAddress, 115, 62); 
     doc&#46;textEx(clientTown, 115, 69); 
     doc&#46;textEx(clientCounty, 115, 76); 
     doc&#46;textEx(clientPostcode, 115, 83); 

     &#47;&#47; Invoice Detail 
     doc&#46;setFontSize(14); 
     doc&#46;rect(20, 110, 170, 100); 
     doc&#46;rect(160, 110, 30, 110); 
     doc&#46;textEx(productDescription, 25, 130); 
     doc&#46;textEx(invoiceAmount&#46;formatMoney(), 187, 130, 'right'); 

     doc&#46;textEx('VAT', 155, 200, 'right'); 
     doc&#46;textEx(invoiceVatAmount&#46;formatMoney(), 187, 200, 'right'); 

     doc&#46;textEx('Total', 155, 213, 'right'); 
     doc&#46;textEx((invoiceAmount + invoiceVatAmount)&#46;formatMoney(), 187, 213, 'right'); 

     &#47;&#47;VAT Number 
     doc&#46;setFontSize(10); 
     doc&#46;textEx('VAT Registration Number: ' + traderVatNumber, 105, 280, 'center'); 
     var uristring = doc&#46;output('datauristring'); 

     &#47;&#47; the email plugin uses a non-standard URI format, so the filename can be specified&#46; 
     if (filename) { 
         var uristringparts = uristring&#46;split(','); 
         uristringparts[0] = "base64:" + escape(filename) + "&#47;&#47;"; 

         var moddeduristring = uristringparts&#46;join(""); 
         return moddeduristring; 
     } else { 
         return uristring; 
     } 
 }, 
 displayPDF: function(uristring) { 
     var ref = window&#46;open(uristring, "_blank", "EnableViewPortScale=yes,location=no,disallowoverscroll=yes,allowInlineMediaPlayback=yes,toolbarposition=top,transitionstyle=fliphorizontal"); 
     return ref; 
 }, 
 createAndDisplayPDF: function(filename) { 
     var uristring = this&#46;createPDF(filename); 
     var ref = this&#46;displayPDF(uristring); 
     return ref; 
 }, 
 emailPDF: function(datauri) { 
     uploadBinaryHelper(emailService, datauri); 
 }, 
 createAndEmailPDF: function(filename) { 
     var uristring = this&#46;createPDF(filename); 
     this&#46;emailPDF(uristring); 
 } 

};

console&#46;log('InvoicePDFCreator ',InvoicePDFCreator);

InvoicePDFCreator&#46;createAndEmailPDF();
/pre

I know that uploadBinaryHelper() is being called because the email is sent. For some reason, there is no attachment.

Terry Gilliver
Posts: 0
Joined: Fri Apr 18, 2014 8:45 pm

Sendgrid

I have given up with sendgrid and decided to use my own rest service to send emails using PHPMailer. Much easier

Moez Ali
Posts: 0
Joined: Wed Aug 17, 2016 2:46 pm

Sendgrid

phpmailer work in appery.io ?

Terry Gilliver
Posts: 0
Joined: Fri Apr 18, 2014 8:45 pm

Sendgrid

No, I have my own service written in php on a separate server, I wrote a function on that server which is executed using a rest service from appery.io

Moez Ali
Posts: 0
Joined: Wed Aug 17, 2016 2:46 pm

Sendgrid

can you please give me that php code i need it i have to deploy in my project

Terry Gilliver
Posts: 0
Joined: Fri Apr 18, 2014 8:45 pm

Sendgrid

if you give me your email address, I will happily send you the php rest service. You can modify it for your own needs. It is just too large to post here.

Moez Ali
Posts: 0
Joined: Wed Aug 17, 2016 2:46 pm

Sendgrid

a href="mailto:moez.mir@gmail.com" rel="nofollow"moez.mir@gmail.com/a and also tell me your phpmailer
working fine on appery.io

Terry Gilliver
Posts: 0
Joined: Fri Apr 18, 2014 8:45 pm

Sendgrid

Yes, it's working fine, but remember it is not running directly on appery it is running on a separately hosted system which runs PHP and MySQL. I am connecting to that system using appery.io rest services. The PHP program itself is a rest server based on Jacob Wright's PHP Rest server available on Github: http://github.com/jacwright/RestServer. I will email you my implmentation of the rest server

You are welcome to use any code as you see fit.

Return to “Issues”