0

I can make calls to Gmail API and retrieve list of messages/thread in JSON.

I want to display these threads/messages to my users in HTML similar to a webmail like gmail itself.

Is there a html+css+js library or template out there that is designed to work with gmail API JSON outputs to display the messages nicely?

Seeker
  • 1,250
  • 1
  • 16
  • 23

1 Answers1

1

You may check on this related thread. It is stated that Email messages that have both HTML and plain text content will have multiple payload parts, and the part with the mimeType "text/html" will contains the HTML content. You can find it with logic like:

var part = message.parts.filter(function(part) {
  return part.mimeType == 'text/html';
});
var html = urlSafeBase64Decode(part.body.data);

You can also check on this link how to parse JSON from Gmail API using JavaScript. Use filter function as follows:

var extractField = function(json, fieldName) {
  return json.payload.headers.filter(function(header) {
    return header.name === fieldName;
  })[0];
};
var date = extractField(response, "Date");
var subject = extractField(response, "Subject");
Community
  • 1
  • 1
abielita
  • 13,147
  • 2
  • 17
  • 59
  • Thank you and those are helpful. However, my question is if there is a library out there that I can through the json respond of list of messages at it and it spits out a html file nicely formatted. I just don't want to reinvent the wheel :) – Seeker Nov 11 '16 at 15:26