0

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.

  • I've run into the same issue, please share a solution if you can find one! – atefth Apr 27 '16 at 04:11
  • 2
    If you're using Gmail, the [Ruby Gmail gem](https://github.com/gmailgem/gmail) is actually quite pleasant to use. If you're stuck using Mail, at least use IMAP, that protocol is way more efficient. – tadman Apr 27 '16 at 05:05
  • 1
    @tadman, Thanks for you reply. Unfortunately I am not using gmail. May be in my case, I'll have to use Net::POP3 or Net::IMAP, with the Mail. Mainly Mail only support singleton retrieve method. Mail will not serve my purpose. –  Apr 27 '16 at 09:10

1 Answers1

1

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.