How to add attachment to gmail api in js

182 Views Asked by At

I am trying to add couple of image attachments in google api, I am not able to find any kind of solution for it, though I am able to send mail without it, can any one help on adding attachments.

const encodedMail = btoa([
  `From: ${guest_email}\r\n`,
  `To: ${toHotel}\r\n`,
  `Subject: ${fullname} Sent Mail\r\n\r\n`,
  `Hello There\n\n I have Just Mailed, Please find my details\n\n Name: ${fullname}\n 
     Phone: ${phone}\n `
].join('')).replace(/\+/g, '-').replace(/\//g, '_');

const response = await fetch(url, {
  method: 'POST',
  mode: 'cors',
  cache: 'no-cache',
  credentials: 'same-origin',
  headers: {
    'Authorization': 'Bearer ' + accessToken,
    'Content-Type': 'application/json'
  },
  redirect: 'follow',
  referrerPolicy: 'no-referrer',
  body: JSON.stringify({
    'raw': encodedMail
  })
});

if (response) {
  console.log(response)
}

Help would be really appreciated.

0

There are 0 best solutions below