Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

151
Views
JS envía un archivo pdf con Microsoft Graph

Estoy tratando de enviar un correo electrónico con un archivo pdf adjunto a través de Microsoft graph api.

Sin un archivo adjunto, el siguiente código funciona perfectamente:

Del lado del cliente

 await axios.get( '/extApi/sp/sendMail', { params: { userId: 'me', sendMail: { message: { subject: 'Meet for lunch?', body: { contentType: 'Text', content: 'The new cafeteria is open.' }, toRecipients: [ { emailAddress: { address: 'myadress@gmail.com' } } ], }, saveToSentItems: 'false', } } });

Lado del servidor

 async function sendMail(req, res) { const options = { authProvider, }; const client = Client.init(options); const sendMail = req.query.sendMail await client.api('/me/sendMail') .post(sendMail); }

Ahora me gustaría adjuntar un archivo pdf. Así que lo intenté sin éxito (mismo código del lado del servidor):

Lado del cliente

 let selectedFile = document.getElementById('file').files[0]; function getBase64(file) { return new Promise((resolve, reject) => { const reader = new FileReader(); reader.readAsDataURL(file); reader.onload = () => resolve(reader.result); reader.onerror = error => reject(error); }); } var encoded = await getBase64(selectedFile) console.log(encoded) await axios.get( '/extApi/sp/sendMail', { params: { userId: 'me', sendMail: { message: { subject: 'Meet for lunch?', body: { contentType: 'Text', content: 'The new cafeteria is open.' }, attachments: [{ "@odata.type": "#microsoft.graph.fileAttachment", "name": "attachment.pdf", "contentType": "application/pdf", "contentBytes": encoded }], toRecipients: [ { emailAddress: { address: 'myadress@gmail.com' } } ], }, saveToSentItems: 'false', } } });

El error aquí es "net::ERR_CONNECTION_RESET 431 (Request Header Fields Too Large)" debido a que la variable "codificada" es muy larga cuando se envía en el lado del servidor. ¿De qué otra manera puedo hacer que funcione?

Gracias

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!