我面临着API的几个问题,
第一:
请求“id”(消息id或线程id)的发送方法。但为什么?我在发新信息所以不需要。根据Gmail Api文档,它是可选的。https://developers.google.com/gmail/api/v1/reference/users/messages/send
ArgumentError: Missing required parameters: id.第二:
即使在指定消息id之后,它也返回此消息。
Your client has issued a malformed or illegal request.代码
require 'mime'
include MIME
msg = Mail.new
msg.date = Time.now
msg.subject = 'This is important'
msg.headers.set('Priority', 'urgent')
msg.body = Text.new('hello, world!', 'plain', 'charset' => 'us-ascii')
msg.from = {'hi@gmail.com' => 'Boss Man'}
msg.to = {
'list@example.com' => nil,
'john@example.com' => 'John Doe',
'jane@example.com' => 'Jane Doe',
}
@email = @google_api_client.execute(
api_method: @gmail.users.messages.send(:get),
body_object: {
raw: Base64.urlsafe_encode64(msg.to_s)
},
parameters: {
userId: 'me'
}
)当然,认证也能正常工作。
其他一些方法也很好。
像这样:
get list of messages(Users.messages.list)
get single message(Users.messages.get)但
发送信息不起作用。
发布于 2015-01-16 09:31:13
我认为您可能会看到我刚刚构建的使用Gmail API而不是像其他宝石一样使用IMAP和SMTP的gem:
gem install gmail-api-ruby
m = Gmail::Message.new(to: test@test.com, subject: "hello", html: "<b>this is html part<b>, text: "this is the text part")
m.deliver它附带了许多在Gmail接口中使用的有用方法。
https://stackoverflow.com/questions/25396463
复制相似问题