Search code examples
ruby-on-railsrubycronemailmail-gem

How to retrieve emails from multiple emails addresses using pop3 of gem mail in Rails?


in my project I will have to write different cron jobs to read emails from different email addresses to do different tasks. I am using mail gem but the problem is, retriever_method is singleton. So when I'll mention the new email address and new password the previous settings of retriever_method will be changed. So, I am not able to retrieve the emails when cron jobs are running at the same time.

Suppose, In my first cron job I have something like the following settings

Mail.defaults do
  retriever_method :pop3, :address    => "pop.gmail.com",
                      :port       => 995,
                      :user_name  => '<username1>',
                      :password   => '<password1>',
                      :enable_ssl => true
end

In my second cron job, If I use something like

:user_name => '<username2>',
:password => '<password1>'

In that case both will be changed to username2

is there any workaround. Or any other suggestion to do this job. I don't want to IMAP for some other reason.

Any suggestion will be appreciated.


Solution

  • Mail retrieve_method is singleton. so I am using Net::IMAP directly with the Mail to retrieve the attachment. One can use Net::Pop3 with Mail as well to resolve this issue.