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

110
Views
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
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!