Skip to content
This repository has been archived by the owner on Nov 27, 2018. It is now read-only.

Problem getting message body in Gmail #151

Open
jedrekdomanski opened this issue Jul 2, 2017 · 1 comment
Open

Problem getting message body in Gmail #151

jedrekdomanski opened this issue Jul 2, 2017 · 1 comment

Comments

@jedrekdomanski
Copy link

jedrekdomanski commented Jul 2, 2017

I have a problem getting body from the message. No matter if I call message.body.decoded or message.text_part.body.decoded the message body in Gmail looks like this:

--94eb2c0dea2087156d055350fc6b
Content-Type: text/plain; charset="UTF-8"

Hello, world!

--94eb2c0dea2087156d055350fc6b
Content-Type: text/html; charset="UTF-8"

<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Hello, world!</div></div>

--94eb2c0dea2087156d055350fc6b--

This is my code:

Mailman::Application.run do
  default do
    begin
      Ticket.receive_mail(message)
    rescue Exception => e
      Mailman.logger.error "Exception occurred while receiving message:\n#{message}"
      Mailman.logger.error [e, *e.backtrace].join("\n")
    end
  end
end

class Ticket < ApplicationRecord
  def self.receive_mail(message)
    
    puts message.body.decoded
    
  end
end

I know that Gmail delivers mails both in text and html but I want just text. I have tried:

puts message.text_part.body.decoded

But it doesn't work

Can you help me?

@jedrekdomanski
Copy link
Author

Got it!

if message.multipart?
  @body = message.text_part.decoded
end

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant