使用GMAIL发送API发送的电子邮件显示在已发送但不在收件箱线程中

时间:2018-04-12 07:58:16

标签: ruby-on-rails google-api gmail-api google-api-ruby-client

我正在使用Gmail的Ruby API来回复邮件。 我的外发邮件具有相同的主题,引用,回复标题。 但是我发送的消息不会作为现有线程的一部分显示在收件箱中。

以下是我的代码的样子:

client = Google::Auth::ClientId.from_file(ENV["CLIENT_SECRETS_PATH"])

service = Google::Apis::GmailV1::GmailService.new
service.client_options.application_name = ENV["APPLICATION_NAME"]
scope = []
scope << 'https://www.googleapis.com/auth/gmail.modify'
service.authorization = Google::Auth::UserRefreshCredentials.new(token_credential_uri: 'https://www.googleapis.com/oauth2/v4/token',
                                                                      client_id: client.id,
                                                                      client_secret: client.secret,
                                                                      refresh_token: data["refresh_token"],
                                                                      scope: scope)
m = MIME::Mail.new
m.to=data["to"]
m.from=data["from"]
m.subject=data["subject"]
m.body= Text.new(data["body"], 'html')
**m.in_reply_to=data["reply_to"]** # This is the Message-ID of the message I want to reply to.
**m.references=data["reply_to"]**  # This is the Message-ID of the message I want to reply to.

message_object = Google::Apis::GmailV1::Message.new(raw:m.to_s)                 
response = service.send_user_message("me", message_object)

0 个答案:

没有答案