node.js - 身体获取节点-imap
问题描述
我需要在 nodejs 中使用 imap 获取邮件正文
imap.openBox("INBOX", true, function(err, box) {
imap.search(['ALL', ['BODY', 'Powered by']], function(err, results){
let f = imap.fetch(results, {bodies: ['HEADER.FIELDS (FROM)', 'HEADER.FIELDS (TO)', 'HEADER.FIELDS (SUBJECT)', 'HEADER.FIELDS (MESSAGE-ID)', 'HEADER.FIELDS (REFERENCES)', 'TEXT']});
f.on('message', function(msg, seqno) {
msg.on('body', function(stream, info) {
let buffer = '', count = 0;
stream.on('data', function(chunk) {
buffer += chunk.toString('utf8');
if (info.which === 'TEXT'){
content = buffer;
console.log("Content === > ", content);
}
.............................................
.............................................
这里的内容没有正确获取
Content === > --000000000000e919ec05c1f7b3ec
Content-Type: text/plain; charset="UTF-8"
This is test reply1 from company email
On Mon, May 10, 2021 at 4:25 PM <reply@test.com> wrote:
> This is a test mail from server
--000000000000e919ec05c1f7b3ec
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">This is test reply1 from company=C2=A0email</div><br><div =
class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Mon, May 10,=
2021 at 4:25 PM <<a href=3D"mailto:reply@test.com">reply@test.com</=
a>> wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0p=
x 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Th=
is is a test mail from server</blockquote></div>
--000000000000e919ec05c1f7b3ec--
一些不需要的字符出现,例如 --000000000000e919ec05c1f7b3ec 和内容类型。我只需要获取邮件正文。如何得到它?
解决方案
推荐阅读
- android - Google Play 应用内购买 - 服务器端验证
- python - 在运行我的 python 代码时,它给了我错误“ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败 (_ssl.c:726)”
- javascript - 如何在表格的同一行上获取多个按钮?
- typescript - 在 TypeScript 中获取带有值字符串(反向映射)的枚举键
- highcharts - 使用 boost 在缩放范围内没有点时显示放大的系列线
- mysql - 使用带有 knex.js 的 leftjoin 仅将 where 条件应用于辅助表
- sql-server - 在 SQL Server 中使用 :out 和变量
- python - 在python中使用直方图颜色范围获取二进制图像
- mongodb - 从集合 mongoDB 中的数组中查询文档
- javascript - 如何使用 JPEG 图像生成器并将其转换为视频流?