来自电子邮件的回复
Response from email
我正在使用 cloudmailin 并接收所有回复邮件(如果有人回复我发送给他们的电子邮件),现在当我执行 request.raw() 时,我得到的所有回复都是字符串格式,如下所示:
{
"headers": {
"received": "xxx.google.com with SMTP id c1so1731393vsh.8 for <xxxx@cloudmailin.net>; Sun, 06 Jun 2021 20:19:02 -0700",
"date": "Mon, 07 Jun 2021 08:48:53 +0530",
"from": "ABC <xxx@gmail.com>",
"to": "xxx@cloudmailin.net",
"message_id": "<xxx@mail.gmail.com>",
"in_reply_to": "<xxx@gmail.com>",
"references": "<xxx@gmail.com>",
"subject": "Re: Update On Your Ticket #66",
"mime_version": "1.0",
"content_type": "multipart/alternative; boundary=000000000000c465af05c4248031",
"dkim_signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=bD3ONqLV7AId5UzdUHe8gDLobCQrtQFYsq2u/8iYIhk=; b=CEHWz5AC3REury8SN4wyg8wxum9H0CmXqT3XJTOjdP0pa5YpCXHPUDMjjLgYf0upd6 rM7qOI7GGHmzNGATmjxu/iQhRD5VaVxOi/VBrExMwlbFzXz8Dg6PoILI2dDnn5oZuzWi zwujwLEVm7VcY2hetWrJYlBfzL5FtSa5W7gZDH42EyqYTDyzLPhWYBPueCSjqfgbXfWH Wb2roecATRV+W9GQZNF7oOKbvpW5ASjzys7a5Llo2xkVfqlvsJli5aIFlUoY1nozj/v7 D/0zkojKlmyDUGEqRxrcIU8JFPm8gl0Ctnx1GgjiZ2vkvWv9oUNpMZdQU3khTbO8WzSV ss7Q==",
"x_google_dkim_signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to;
bh=bD3ONqLV7AId5UzdUHe8gDLobCQrtQFYsq2u/8iYIhk=; b=Zs0h+EM3gcygNli6sm5CpodTr1kziEkj+W5ceiKiaGo2XZVMOXq85IZBY5jaOUspmF R15pIV36BDP1mI2y0GbRE+jcIq7I6MjIxpDusRrxMDnADYyS5jRNk2YfqJC+4ml2MLSz LGX+4JugPBp4QJq1dDPAGrqP8hfrXNLXcDZx7rUck9LCgbP59nUvDNndYUcbF45xa+oV RvCvYo7ue69ogrc+/DM1b2uzP+lU7oY68yFhpfEGctWGaj36vsOcgrSA+FM7bB0UChWI HVhRwFIzq+tdKH+lJvqMbnxeCSqSL8p0TofGHEKfN4D+POaYVLW59wegz5i7K2Vdpq/l Spog==",
"x_gm_message_state": "AOAM533Hi5baxQtGjkRr4KU1AyKeRfihKQKBKyyQu6Si4uto+Fy8F1jB\tZamxinSc8qQ6vbsNhXqvOvuhBP5iFo23kcz2DEfqY28=",
"x_google_smtp_source": "ABdhPJzSzz9bec+GYLzqjqOWnZ4BOEmm8Yt56FcCc0cr2D6Pag5pWL+Qq2Q7SBXzw+7gBxq1onhFX1KhlhE6yjxuyu4=",
"x_received": "by 2002:a05:6102:dca:: with SMTP id e10mr2789248vst.47.1623035941773; Sun, 06 Jun 2021 20:19:01 -0700 (PDT)"
},
"envelope": {
"to": "xxx@cloudmailin.net",
"recipients": [
"xxx@cloudmailin.net"
],
"from": "xxx@gmail.com",
"helo_domain": "xxx.google.com",
"remote_ip": "abc.de.fg.ql",
"tls": true,
"tls_cipher": "TLSv1.3",
"md5": "xxx",
"spf": {
"result": "neutral",
"domain": "gmail.com"
}
},
"plain": "Yes, what about you?\n\nOn Mon, Jun 7, 2021 at 8:48 AM <xxx@gmail.com> wrote:\n\n> xxx@gmail.com replied to your ticket\n>\n> Message: all cool?\n>\n",
"html": "<div dir=\"ltr\">Yes, what about you?</div><br><div class=\"gmail_quote\"><div dir=\"ltr\" class=\"gmail_attr\">On Mon, Jun 7, 2021 at 8:48 AM <<a href=\"mailto:xxx@gmail.com\">xxx@gmail.com</a>> wrote:<br></div><blockquote class=\"gmail_quote\" style=\"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex\"><a href=\"mailto:xxx@gmail.com\"
target=\"_blank\">xxx@gmail.com</a> replied to your ticket <br><p>Message: all cool?</p>\r\n</blockquote></div>\r\n",
"reply_plain": "Yes, what about you?",
"attachments": [
]
}
如何仅从该消息中获取 html
部分?我无法遍历该对象,因为它是一个字符串,从整个数据中我只需要消息的 html 部分。
你能帮我解决这个问题吗?
使用 JSON.parse() 将响应字符串解析为 JSON 对象。从那里,您可以使用标准 属性 访问权限来获取您需要的值。
示例:
const data = JSON.parse(....);
const html = data.html;
const subject = data.headers.subject;
我正在使用 cloudmailin 并接收所有回复邮件(如果有人回复我发送给他们的电子邮件),现在当我执行 request.raw() 时,我得到的所有回复都是字符串格式,如下所示:
{
"headers": {
"received": "xxx.google.com with SMTP id c1so1731393vsh.8 for <xxxx@cloudmailin.net>; Sun, 06 Jun 2021 20:19:02 -0700",
"date": "Mon, 07 Jun 2021 08:48:53 +0530",
"from": "ABC <xxx@gmail.com>",
"to": "xxx@cloudmailin.net",
"message_id": "<xxx@mail.gmail.com>",
"in_reply_to": "<xxx@gmail.com>",
"references": "<xxx@gmail.com>",
"subject": "Re: Update On Your Ticket #66",
"mime_version": "1.0",
"content_type": "multipart/alternative; boundary=000000000000c465af05c4248031",
"dkim_signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=bD3ONqLV7AId5UzdUHe8gDLobCQrtQFYsq2u/8iYIhk=; b=CEHWz5AC3REury8SN4wyg8wxum9H0CmXqT3XJTOjdP0pa5YpCXHPUDMjjLgYf0upd6 rM7qOI7GGHmzNGATmjxu/iQhRD5VaVxOi/VBrExMwlbFzXz8Dg6PoILI2dDnn5oZuzWi zwujwLEVm7VcY2hetWrJYlBfzL5FtSa5W7gZDH42EyqYTDyzLPhWYBPueCSjqfgbXfWH Wb2roecATRV+W9GQZNF7oOKbvpW5ASjzys7a5Llo2xkVfqlvsJli5aIFlUoY1nozj/v7 D/0zkojKlmyDUGEqRxrcIU8JFPm8gl0Ctnx1GgjiZ2vkvWv9oUNpMZdQU3khTbO8WzSV ss7Q==",
"x_google_dkim_signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to;
bh=bD3ONqLV7AId5UzdUHe8gDLobCQrtQFYsq2u/8iYIhk=; b=Zs0h+EM3gcygNli6sm5CpodTr1kziEkj+W5ceiKiaGo2XZVMOXq85IZBY5jaOUspmF R15pIV36BDP1mI2y0GbRE+jcIq7I6MjIxpDusRrxMDnADYyS5jRNk2YfqJC+4ml2MLSz LGX+4JugPBp4QJq1dDPAGrqP8hfrXNLXcDZx7rUck9LCgbP59nUvDNndYUcbF45xa+oV RvCvYo7ue69ogrc+/DM1b2uzP+lU7oY68yFhpfEGctWGaj36vsOcgrSA+FM7bB0UChWI HVhRwFIzq+tdKH+lJvqMbnxeCSqSL8p0TofGHEKfN4D+POaYVLW59wegz5i7K2Vdpq/l Spog==",
"x_gm_message_state": "AOAM533Hi5baxQtGjkRr4KU1AyKeRfihKQKBKyyQu6Si4uto+Fy8F1jB\tZamxinSc8qQ6vbsNhXqvOvuhBP5iFo23kcz2DEfqY28=",
"x_google_smtp_source": "ABdhPJzSzz9bec+GYLzqjqOWnZ4BOEmm8Yt56FcCc0cr2D6Pag5pWL+Qq2Q7SBXzw+7gBxq1onhFX1KhlhE6yjxuyu4=",
"x_received": "by 2002:a05:6102:dca:: with SMTP id e10mr2789248vst.47.1623035941773; Sun, 06 Jun 2021 20:19:01 -0700 (PDT)"
},
"envelope": {
"to": "xxx@cloudmailin.net",
"recipients": [
"xxx@cloudmailin.net"
],
"from": "xxx@gmail.com",
"helo_domain": "xxx.google.com",
"remote_ip": "abc.de.fg.ql",
"tls": true,
"tls_cipher": "TLSv1.3",
"md5": "xxx",
"spf": {
"result": "neutral",
"domain": "gmail.com"
}
},
"plain": "Yes, what about you?\n\nOn Mon, Jun 7, 2021 at 8:48 AM <xxx@gmail.com> wrote:\n\n> xxx@gmail.com replied to your ticket\n>\n> Message: all cool?\n>\n",
"html": "<div dir=\"ltr\">Yes, what about you?</div><br><div class=\"gmail_quote\"><div dir=\"ltr\" class=\"gmail_attr\">On Mon, Jun 7, 2021 at 8:48 AM <<a href=\"mailto:xxx@gmail.com\">xxx@gmail.com</a>> wrote:<br></div><blockquote class=\"gmail_quote\" style=\"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex\"><a href=\"mailto:xxx@gmail.com\"
target=\"_blank\">xxx@gmail.com</a> replied to your ticket <br><p>Message: all cool?</p>\r\n</blockquote></div>\r\n",
"reply_plain": "Yes, what about you?",
"attachments": [
]
}
如何仅从该消息中获取 html
部分?我无法遍历该对象,因为它是一个字符串,从整个数据中我只需要消息的 html 部分。
你能帮我解决这个问题吗?
使用 JSON.parse() 将响应字符串解析为 JSON 对象。从那里,您可以使用标准 属性 访问权限来获取您需要的值。
示例:
const data = JSON.parse(....);
const html = data.html;
const subject = data.headers.subject;