Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

112
Vistas
Create HTML formatted draft using Gmail API and Javascript

I have a div which contains some html that I want to use as an email template. I first successfully created my function to add a draft email with a plain text but when I try to create the draft using the div html contents something breaks. So I then attempted to use base64 encode the div contents and create a draft just put the encoded string in the body of the email instead of being decoded back into my html. So no I am at a loss and was wondering if anybody had any thoughts on what I'm doing wrong.

function sendMessage(headers_obj, message, callback)
{
var email = '';

for(var header in headers_obj)
  email += header += ": "+headers_obj[header]+"\r\n";

newmessage =  Base64.encodeURI(message);
email += "\r\n" + newmessage;
email = window.btoa(email).replace(/\+/g, '-').replace(/\//g, '_');

gapi.client.load('gmail', 'v1', function() {
    var request = gapi.client.gmail.users.drafts.create({
      'userId': "me",
      'resource': {
           'message': {
           'raw': email
         },
         }
    });
    request.execute(function(callback){
      console.log(callback)
    });
  });
}
about 4 years ago · Santiago Gelvez
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda