how to send message using Gmail API with Ruby Google API Client?

☆樱花仙子☆ 提交于 2019-11-28 11:35:38

I think

@gmail.users.messages.send(:get) is equal to @gmail.users.messages.get

because ".send" is ruby method

so now this method is working with

@gmail.users.messages.to_h['gmail.users.messages.send']

example:

msg = Mail.new
msg.date = Time.now
msg.subject = options[:subject]
msg.body = Text.new(options[:message])
msg.from = {@_user.email => @_user.full_name}
msg.to   = {
    options[:to] => options[:to_name]
}
@email = @google_api_client.execute(
    api_method: @gmail.users.messages.to_h['gmail.users.messages.send'],
    body_object: {
        raw: Base64.urlsafe_encode64(msg.to_s)
    },
    parameters: {
        userId: 'me',
    }
) 

Thanks.

I think you may have a look at this gem I just built that use Gmail API and not using IMAP and SMTP like other gems:

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-api-ruby

It comes with a lot of helpful methods that you use in Gmail interface

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!