Tisamu Tisamu - 1 year ago 80
Ruby Question

Receive Mails with Rails

I would like to scrap mails from a MailBox, this is the situation:

It's about a Technical support with a Ticket System.

A client make a demand on the contact form on the website,
The ticket have a page with a chat and a task list made by the admin in charge of the ticket, so a link to this page is sent to the client who made the demand,

Then when the Admin answer to the ticket in the chat, a mail is sent to the Client, everything to there is ok, the problem is that when the client answer to this email, the content of the mail must be scrapped and added to the database to be seen in the Ticket Chat.

So the Idea is that the Client Can follow the progress of his Ticket by mail instead of going to the ticket page.

I've tried MailMan, but that didn't work, the deamon was starting and then crashed after a couple of minutes whitout scrapping anything, I don't use SendGrid but a private SMTP server so I can't use the Grabber gem of this service.

I'm running Rails 5, my DB is in PostGre, and I'm using ActionMailer as mailing system.

I'm running out of ideas about how to make this feature..

I hope my question is clear enough and my English not too bad.

Answer Source

I suggest you to make an email(any popular provider except gmail) box and configure it to use a pop server. To read it from the box use the mail gem.

Mail.defaults do
  retriever_method :pop3, :address    => "pop.supermail.com",
                          :port       => 995,
                          :user_name  => '<username>',
                          :password   => '<password>',
                          :enable_ssl => true

Then make a daemon to read all income emails and save it to the database, mail gem is just a wrapper around Net::POP3 ruby library and it is super useful for read\receive\parse\build mails.

The ActionMailer here is not a helper for you, it is very handy only for send mails and it does nothing to recieve mail.