Ruby on rails 3.1 Incoming Email with th Mailman Gem
-
14-11-2019 - |
Pergunta
I'm researching a solution for a client, where they receive orders through email. I understand that with the Mailman gem I can setup a server to fetch mail then parse attributes such as from, subject, body, etc. My question is what solution do i need to further analyze or scrape the body for attributes such as po number, quantity, price, department etc? I was thinking that if the email body had a very strict format I could do this, but it seems mailman matchers cannot get this specific. In addition I need to reply to each email to accept the order when a technician receives the order.
Solução
You could parse the body with nokogiri:
body_html = Nokogiri::HTML(your_body_variable_here)
body_html.css("#price").each do |p|
# do whatever you want with each price
end
As for the reply to, you can loop trough the from variable of Mailman, ie:
message.from.each do |from|
# do something
end
By the way, I did not test that code, just wrote it as I remember it to help you quickly...