# Sendgrid & attachement update

**URL:** <https://forum.wixstudio.com/t/sendgrid-attachement-update/613>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [May 12, 2021, 8:52pm UTC](https://forum.wixstudio.com/t/sendgrid-attachement-update/613 "2021-05-12T20:52:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fzupan](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/fzupan/32/11984_2.png) [@fzupan](https://forum.wixstudio.com/u/fzupan)\
**Post date:** [May 12, 2021, 8:52pm UTC](https://forum.wixstudio.com/t/sendgrid-attachement-update/613/1 "2021-05-12T20:52:41Z")

</div>

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:  
[https://www.wix.com/velo/forum/coding-with-velo/file-attachment-using-sendgrid-api](https://www.wix.com/velo/forum/coding-with-velo/file-attachment-using-sendgrid-api)

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

```javascript
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 ={       
to:'test1@gmail.com',
from:'no-reply@gmail.com',       
subject:'Hello attachment',       
html:`<p>Here’s an attachment for you!</p><br> <br> Thanks`,     
attachments:[{         
content: base64File,         
filename:'My_PDF.pdf',//replace dynamically if needed         
type:'plain/text',         

disposition:'attachment',         
contentId:'mytext'},],};
return sgMail.send(msg)
.then(function(err, 
response){if(err){return err;}return response;})
.catch((err)=>{return err;});}

```

---

<div class="post-metadata">

**Author:** ![fzupan](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/fzupan/32/11984_2.png) [@fzupan](https://forum.wixstudio.com/u/fzupan)\
**Post date:** [May 12, 2021, 9:03pm UTC](https://forum.wixstudio.com/t/sendgrid-attachement-update/613/2 "2021-05-12T21:03:54Z")

</div>

@shantanukumar847 update would be amazing!

---

<div class="post-metadata">

**Author:** ![Shan](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/shan/32/106059_2.png) [@Shan](https://forum.wixstudio.com/u/Shan)\
**Post date:** [May 13, 2021, 10:29am UTC](https://forum.wixstudio.com/t/sendgrid-attachement-update/613/3 "2021-05-13T10:29:19Z")

</div>

updated [https://www.wix.com/velo/forum/coding-with-velo/file-attachment-using-sendgrid-api](https://www.wix.com/velo/forum/coding-with-velo/file-attachment-using-sendgrid-api)

---

<div class="post-metadata">

**Author:** ![fzupan](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/fzupan/32/11984_2.png) [@fzupan](https://forum.wixstudio.com/u/fzupan)\
**Post date:** [May 14, 2021, 9:37am UTC](https://forum.wixstudio.com/t/sendgrid-attachement-update/613/4 "2021-05-14T09:37:54Z")

</div>

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?

 ![](https://us1.discourse-cdn.com/wix/original/3X/2/a/2ade28855678e918aa50d595d3fa6b0e2d789e51.png)

---

<div class="post-metadata">

**Author:** ![fzupan](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/fzupan/32/11984_2.png) [@fzupan](https://forum.wixstudio.com/u/fzupan)\
**Post date:** [May 14, 2021, 3:17pm UTC](https://forum.wixstudio.com/t/sendgrid-attachement-update/613/5 "2021-05-14T15:17:47Z")

</div>

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