Sendgrid & attachement update

Hi coders

since " request-promise" is not working any more, can someone update the code, how to use it with " node-fetch" or alternatives as recommended in the following post:

I am still not familiar with this concept and don’t know what result I need for starting base64 encode
Thanks for your help guys!

j Florian

import sgMail from"@sendgrid/mail";
import request from"request-promise";
import encode from"nodejs-base64-encode";
const apiKey ="SG.XXXXXX";//api key//pass the url of the file from the page. It should be the entire url and not just the url you get after uploading the file using .startUpload()

export function mailing(url){//read above
return request.get(url,{encoding:null})
.then(function(res){var base64File = encode.encode(res,'base64');
return sending(base64File);});}

function sending(base64File){     sgMail.setApiKey(apiKey);const msg ={       
subject:'Hello attachment',       
html:`<p>Here’s an attachment for you!</p><br>       <br>       Thanks`,     
content: base64File,         
filename:'My_PDF.pdf',//replace dynamically if needed         

return sgMail.send(msg)
response){if(err){return err;}return response;})
.catch((err)=>{return err;});}
1 Like

@shantanukumar847 update would be amazing!



Dear @shan
Thanks for your quick replay! I put the code in a JS File and it looks very good but the only think I have trouble with is the .buffer() function which seems to be not supported by wix-fetch?

Any suggestions what I can do here?

Sorry, code works just perfekt! Thanks a lot for the direction!!!