I am trying to display an email body in my RoR project.
class IncomingMail
def initialize(message, params)
if person = Person.find_by_email(message.from)
changeMessage = Message.where({person_id: person.id})
#message = message.subject.force_encoding("UTF-8")
message = message.body.encoded
changeMessage.first.text = message
changeMessage.first.backInMinutes = 0
changeMessage.first.showText = 1
changeMessage.first.doNotDisturb = 0
changeMessage.first.save
end
end
but i also get the email header
> --e89a8ff1c0465030f204c082e054 Date: Mon, 21 May 2012 04:45:12 +0200 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1
> Content-Transfer-Encoding: 7bit Content-ID:
> <[email protected]> Text of the mail
how can I remove the header ?
with the subject it works like this
message = message.subject.force_encoding("UTF-8")
But not with the body.
I have found the solution!!!
change:
to:
that cuts all the header details away and gives me only the TEXT of the email.
It took a long time but it worked I hope it also helps other users