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");