【发布时间】:2018-07-17 19:42:46
【问题描述】:
大家好,目前我正在使用 ruby 构建回复消息,这是我的代码
def reply(user_id, subject, to, body, thread_id)
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 = "#{subject}"
message.from = token.email
message.to = "#{to}"
message.thread_id = "#{thread_id}"
message.part content_type: 'multipart/alternative' do |part|
part.html_part = Mail::Part.new(body: "#{body}", content_type: 'text/html; charset=UTF-8')
end
# attach file
open('/Users/jaisanasrulloh/Downloads/image.png') do |file|
message.attachments['image.jpg'] = file.read
end
msg = message.encoded
message_object = Google::Apis::GmailV1::Message.new(raw:message.to_s)
gmail.send_user_message('me', message_object)
end
但我收到如下错误:
NoMethodError: undefined method `thread_id=' for #<Mail::Message:0x007fcedb6b9c78>
我的问题是如何在 Mail::Message 对象中添加 thread_id ?有人使用类RMail::Message 像这样one
Mail::Message 中是否存在参数 thread_id ?有的话怎么添加?
【问题讨论】:
-
查看documentation 以进一步帮助您。据说
If you are sending or migrating messages that are a response to another email or part of a conversation, your application should add that message to the related thread. This makes it easier for Gmail users who are participating in the conversation to keep the message in context. -
是的,我知道可以给你详细的例子可能是?
标签: ruby google-api gmail-api google-api-ruby-client