Work through sending gmail with the new google-api-ruby client in rails 4 app.
require 'google/apis/gmail_v1'
Gmail = Google::Apis::GmailV1
class MailService
def initialize(params)
@params = params
end
def call
message = Gmail::Message.new
service = Gmail::GmailService.new
message.raw = (redacted)
service.request_options.authorization = current_user.token.fresh_token
result = service.send_user_message(current_user.email, message)
end
end
And this is the result of calling the API:
Sending HTTP post https:
200
#<Hurley::Response POST https:
Success - #<Google::Apis::GmailV1::Message:0x007fc9cf9b52dd
@id="15096369c05cdb1d",
@thread_id="15096369c05cdb1d">
An unhandled message is sent without problems from the API Explorer, but when it is executed from my application, I get an error message in my inbox. In the example above, the edited sample is a valid RFC 2822 string with source code 64, and fresh_token represents the oauth2 access token for the current user.
Look at the mail bounce
Bounce <nobody@gmail.com>
2:43 PM (19 minutes ago)
to me
An error occurred. Your message was not sent.
Anyone have any thoughts? It looks like maybe my (sending) email was picked up in a raw message, but not in the recipient ... Although I suppose the API can forward failures based on my oauth access token.
. !
EDIT: RFC 2822 base64.