本文介绍了使用Gmail API检索HTML中的电子邮件/邮件正文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用GMail api以html格式检索邮件正文?

Is there any way to retrieve message body in html form using GMail api ?

我已经经历过 message.get 文档.尝试将format参数更改为fullminimal& raw.但这并没有帮助.它返回邮件正文的纯文本.

I have already gone through the message.get docs. Tried changing the format param to full, minimal & raw. But it did not help. It's returning the plain text of mail body.

格式值的描述:

已满":在有效负载字段中返回已解析的电子邮件消息内容,并且不使用原始字段. (默认)

"full": Returns the parsed email message content in the payload field and the raw field is not used. (default)

最小":仅返回电子邮件元数据,例如标识符和标签,不返回电子邮件标头,正文或有效载荷.

"minimal": Only returns email message metadata such as identifiers and labels, it does not return the email headers, body, or payload.

原始":以字符串形式返回原始字段中的整个电子邮件内容,并且不使用有效负载字段.其中包括标识符,标签,元数据,MIME结构和较小的正文部分(通常小于2KB).

"raw": Returns the entire email message content in the raw field as a string and the payload field is not used. This includes the identifiers, labels, metadata, MIME structure, and small body parts (typically less than 2KB).

我们不能简单地以html形式获取消息正文,还是有其他方法可以使邮件在我的应用程序或GMail中看到时以最小的差异显示在屏幕上?

Can't we simply get message body in html form or is there any other way to do this so that mail is displayed on the screen with very minimal difference when they see in my app or GMail ?

推荐答案

同时具有HTML和纯文本内容的电子邮件将具有多个有效负载部分,而mimeType为"text/html"的部分将包含HTML内容.您可以使用以下逻辑找到它:

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

这篇关于使用Gmail API检索HTML中的电子邮件/邮件正文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!