目前我正在尝试使用Gmail API创建发送和回复,文档在这里。
必须按照RFC 2822标准设置“References”和“In-Reply-To”,但问题是当我尝试从指定的ID获取“References”和“In-Reply-To”时,如下所示:
当您查看结果时,没有标题
以下是我在Ruby中的代码:
这段代码可以成功发送邮件在同一线程中,但无法回复邮件。以下是我的Gmail已发送邮件的样子: 如您所见,正文为“lauv”的消息并没有回复“terkait”消息,而是我只是发送了电子邮件“lauv”,我的问题是如何回复电子邮件?
必须按照RFC 2822标准设置“References”和“In-Reply-To”,但问题是当我尝试从指定的ID获取“References”和“In-Reply-To”时,如下所示:
`{
"id": "16183e0822247c79",
"threadId": "16183e0822247c79",
"labelIds": [
"SENT"
],
"snippet": "terkait",
"historyId": "1640387",
"internalDate": "1518335984000",
"payload": {
"partId": "",
"mimeType": "multipart/mixed",
"filename": "",
"headers": [
{
"name": "Received",
"value": "from 1059028371380 named unknown by gmailapi.google.com with HTTPREST; Sat, 10 Feb 2018 23:59:44 -0800"
},
{
"name": "Date",
"value": "Sat, 10 Feb 2018 23:59:44 -0800"
},
{
"name": "From",
"value": "jaisanas2@gmail.com"
},
{
"name": "To",
"value": "jaisanas3@gmail.com"
},
{
"name": "Message-Id",
"value": "\u003cCA+8aSZeXMOETdH8NYtd18UWk5eiQnvT0oEnEWy_1HL6mJPuKjw@mail.gmail.com\u003e"
},
{
"name": "Subject",
"value": "terkait"
},
{
"name": "Mime-Version",
"value": "1.0"
},
{
"name": "Content-Type",
"value": "multipart/mixed; boundary=\"--==_mimepart_5a7ff7f050e3_3263ffa0ceb1cc020ea\"; charset=UTF-8"
},
{
"name": "Content-Transfer-Encoding",
"value": "7bit"
}
],
"body": {
"size": 0
},
"parts": [
{
"partId": "0",
"mimeType": "multipart/alternative",
"filename": "",
"headers": [
{
"name": "Content-Type",
"value": "multipart/alternative; boundary=\"--==_mimepart_5a7ff7f05063_3263ffa0ceb1cc01916\"; charset=UTF-8"
},
{
"name": "Content-Transfer-Encoding",
"value": "7bit"
}
],
"body": {
"size": 0
},
"parts": [
{
"partId": "0.0",
"mimeType": "text/html",
"filename": "",
"headers": [
{
"name": "Content-Type",
"value": "text/html; charset=UTF-8"
},
{
"name": "Content-Transfer-Encoding",
"value": "7bit"
}
],
"body": {
"size": 14,
"data": "PHA-dGVya2FpdDwvcD4="
}
}
]
}
]
},
"sizeEstimate": 929
}`
当您查看结果时,没有标题
In-Reply-To
和Refernces
,我的问题是使用API回复电子邮件是否可能?以下是我在Ruby中的代码:
client = google_client user_id
token = Token.find_by_user_id(user_id)
access_token = token.access_token
gmail = Google::Apis::GmailV1::GmailService.new
gmail.authorization = client
message = Mail.new
message.date = Time.now
message.subject = "Re: #{subject}"
message.from = token.email
message.to = "#{to}"
# message.thread_id = "#{thread_id}"
message.message_id = "\u003cCA+8aSZeXMOETdH8NYtd18UWk5eiQnvT0oEnEWy_1HL6mJPuKjw@mail.gmail.com\u003e"
message.part content_type: 'multipart/alternative' do |part|
part.html_part = Mail::Part.new(body: "#{body}", content_type: 'text/html; charset=UTF-8')
end
msg = message.encoded
message_object = Google::Apis::GmailV1::Message.new(raw:message.to_s, thread_id: thread_id, content_type: 'message/rfc822')
gmail.send_user_message('me', message_object)
这段代码可以成功发送邮件在同一线程中,但无法回复邮件。以下是我的Gmail已发送邮件的样子: 如您所见,正文为“lauv”的消息并没有回复“terkait”消息,而是我只是发送了电子邮件“lauv”,我的问题是如何回复电子邮件?
In-Reply-To
和References
。你可以尝试向一个线程发送一封电子邮件,然后再次使用get.thread(),你会看到In-Reply-To
和References
被填充。当In-Reply-To
和References
的值缺失时,应用回复到线程,并使用In-Reply-To
和References
回复消息以正确回复线程。 - undefined