Mail gem - how to clean up the body string

前端 未结 4 1928
失恋的感觉
失恋的感觉 2021-02-05 19:06

I\'m trying to read an email using ruby mail gem. But mail.body.decoded returns me not just the body message. How can I clean up this body message and remove unwan

4条回答
  •  萌比男神i
    2021-02-05 19:39

    If you have a properly formatted email, you can use Mail helper methods:

    mail = Mail.new(email_string)
    mail.text_part # finds the first text/plain part
    mail.html_part # finds the first text/html part
    

    This doesn't always work if you have e.g. single part messages (text only) or receive email from the internet at large since you can't rely on formatting from every client out there. Believe me, I've learned the hard way.

提交回复
热议问题