title: Rails: Send email using Gmail API with attachment return only encoded file not
body: <p>I am trying to send an email using gmail API. My Ruby code as you can see below works well without an attachment:</p>
  
  <pre><code>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      = 'Supertram p'
  message.body         = "&lt;p&gt;Hi Alex, how's life?&lt;/p&gt;"
  message.content_type = 'text/html'
  message.from         = self.email
  message.to           = 'email_name@gmail.com'
  
  msg = message.encoded
  message_object = Google::Apis::GmailV1::Message.new(raw:message.to_s)
  gmail.send_user_message('me', message_object)
  </code></pre>
  
  <p>I was able to successfully send emails in html format. 
  My question is how to attach a file to this message?</p>
  
  <pre><code>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      = 'Supertramp'
  message.body         = "&lt;p&gt;Hi Alex, how's life?&lt;/p&gt;"
  # message.content_type = 'text/html'
  message.from         = self.email
  message.to           = 'myemail@gmail.com'
  message.add_file("/Users/myname/Downloads/image.png")
  
  msg = message.encoded
  message_object = Google::Apis::GmailV1::Message.new(raw:message.to_s)
  gmail.send_user_message('me', message_object)
  </code></pre>
  
  <p>but here is the message that I receive:</p>
  
  <blockquote>
    <p>-- Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Hi Alex, how's life?</p>
    
    <p>-- Content-Type: image/png; filename=image.png Content-Transfer-Encoding: base64 Content-Disposition: attachment;
    filename=image.png Content-ID:
    &lt;5a6ebb78429d2_e4a3fd9b60336c4945c7@Jaiss-MacBook-Pro.local.mail>
    iVBORw0KGgoAAAANSUhEUgAAAfAAAABMCAYAAACS0+VcAAAX9UlEQVR4Ae2d
    XWxj1bXH/6lKK+D1VE1oKEa6CPNwpQh4SFBapYOrIoGUuRnN6IRR25HuC1C/
    AC8JDMiFGTlP8 [...] == ----</p>
  </blockquote>
  
  <p>I only receive an encoded string, but not an attached file. 
  My question is how to send an email by Gmail API with an attachment?</p>