Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

111
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda