gpt4 book ai didi

ruby-on-rails - 通过 Gmail API 回复发送的电子邮件

转载 作者:太空宇宙 更新时间:2023-11-03 16:41:21 25 4
gpt4 key购买 nike

目前我正在尝试使用 gmail api 创建发送和回复,在文档中 here

ReferencesIn-Reply-To 必须设置为符合 RFC 2822 标准,问题是当我尝试获取 References 和来自指定 ID 的 In-Reply-To,如下所示:

demo request parameter

`{
"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
}`

当您看到结果时没有 header In-Reply-ToRefernces,我的问题是可以使用 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 发送的电子邮件中的样子:

enter image description here

如您所见,正文为 lauv 的消息不会回复消息 terkait 而我只是发送电子邮件 lauv,我的问题是如何回复邮件?

最佳答案

在这里您需要设置 In-Reply-To 和 References header 。如果线程中只有一封电子邮件,请使用 message_id 作为回复和引用

关于ruby-on-rails - 通过 Gmail API 回复发送的电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48729690/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com