Project

General

Profile

Receiving E-mails via cron

Added by Mike T almost 14 years ago

Hi. I am having trouble getting Redmine to check for e-mail from a cron job. I set this up according to the documentation at http://www.redmine.org/wiki/1/RedmineReceivingEmails.

This is what my line in cron looks like. If I run the same thing from a interactive shell, it works (it doesn't put the issue in the triage bin but that's not as important). The same line below does not work when run from cron.

*/1 * * * * /usr/local/bin/rake redmine:email:receive_imap RAILS_ENV="production" host=secure.mailserver.com port=993 username=bugz@mydomain.com password=mypassword ssl=1 project=kcdev tracker=triage

If I run the line with the "-f" argument as specified on the wiki page, I get an error, even when running it at the interactive shell:

[root@redmine redmine]# /usr/local/bin/rake -f /var/www/sites/redmine/lib/tasks/email.rake redmine:email:receive_imap RAILS_ENV="production" host=secure.mailserver.com port=993 username=bugz@mydomain.com password=mypassword ssl=1 project=kcdev tracker=triage
(in /var/www/sites/redmine)
rake aborted!
Don't know how to build task 'environment'

Here is the information on my set-up:

- Ruby implementation and version: ruby 1.8.7 (2010-01-10 patchlevel 249) [x86_64-linux]
- Rails version (rails --version): Rails 2.3.5
- Operating system: CentOS 5.4
- Database used, and its version: MySQL 14.12 Distrib 5.0.77
- Ruby-aware server used: Apache - httpd-2.2.3-31

Does anyone have any ideas on what I'm doing wrong?

Thanks,
Mike


Replies (10)

RE: Receiving E-mails via cron - Added by Felix Schäfer almost 14 years ago

It might be that you have "too much" path in your -f parameter. Works for me with:

*/2 * * * *    apache    /usr/bin/rake -s -f /path/to/redmine/Rakefile redmine:email:receive_imap RAILS_ENV="production" $OTHER_OPTIONS

(IIRC the -s switch just silences the rake call)

RE: Receiving E-mails via cron - Added by Mike T almost 14 years ago

Thanks, Felix. That actually didn't work for me though. On my system, rake lives in /usr/local/bin so /usr/bin/rake doesn't do anything.

I actually got it mostly working now.

Currently, this is the line in cron:

cd /var/www/sites/redmine ; /usr/local/bin/rake redmine:email:receive_imap RAILS_ENV="production" host=secure.mailserver.com port=993 username= password=mypassword unknown_user=accept ssl=1 project=kcdev tracker=triage

Two things had to be done to get IMAP mail fetching working:
  • Change directories to the path of Redmine.
  • remove the "-f" and the rake file path that goes with it. Not sure why that was a problem, especially since the documentation says to do it that way, but oh, well.

There we have it. Mail fetching finally works!

I still have a problem though: Redmine seems to ignore any additional parameters I pass to it so the tracker=triage bit does not work. New issues are not assigned to any particular category or version. That's something I need to correct fairly soon. If anyone has ideas, please let me know.

Thanks again,
Mike

RE: Receiving E-mails via cron - Added by Felix Schäfer almost 14 years ago

You have to specify the tracker exactly as it is named in your redmine installation, i.e. capitalization might be the issue.

RE: Receiving E-mails via cron - Added by Mike T almost 14 years ago

Doh! I put tracker but meant category. That was my problem. Now it assigns tickets to the appropriate category. Yay!

Thanks again!

RE: Receiving E-mails via cron - Added by robin van emden over 12 years ago

Thanks Mike T, removing f and rake file path did the trick for me as well.

RE: Receiving E-mails via cron - Added by Tomasz Mirecki over 5 years ago

Can anyone help poor guy like me?

I have cron: rake -f home/zenmana/domains/zenweb.pl/public_html/Rakefile redmine:email:receive_imap RAILS_ENV="production" host=imap.gmail.com port=993 ssl=1 username= password=mypassword --trace

I got email response:

(in /)
rake aborted!
LoadError: cannot load such file -- bundler/setup
/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/home/zenmana/domains/zenweb.pl/public_html/config/boot.rb:4:in `<top (required)>'
/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/home/zenmana/domains/zenweb.pl/public_html/config/application.rb:1:in `<top (required)>'
/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/home/zenmana/domains/zenweb.pl/public_html/Rakefile:5:in `<top (required)>'
/usr/lib/ruby/vendor_ruby/rake/rake_module.rb:28:in `load'
/usr/lib/ruby/vendor_ruby/rake/rake_module.rb:28:in `load_rakefile'
/usr/lib/ruby/vendor_ruby/rake/application.rb:689:in `raw_load_rakefile'
/usr/lib/ruby/vendor_ruby/rake/application.rb:94:in `block in load_rakefile'
/usr/lib/ruby/vendor_ruby/rake/application.rb:176:in `standard_exception_handling'
/usr/lib/ruby/vendor_ruby/rake/application.rb:93:in `load_rakefile'
/usr/lib/ruby/vendor_ruby/rake/application.rb:77:in `block in run'
/usr/lib/ruby/vendor_ruby/rake/application.rb:176:in `standard_exception_handling'
/usr/lib/ruby/vendor_ruby/rake/application.rb:75:in `run'
/usr/bin/rake:27:in `<main>'

what do I do wrong?

RE: Receiving E-mails via cron - Added by Bernhard Rohloff over 5 years ago

Please check if the command works in your user session.
If this exact line works in your console I'd bet that the PATH variable isn't set correctly.

RE: Receiving E-mails via cron - Added by Tomasz Mirecki over 5 years ago

Thank You, I am like Wordpress coding advanced. I am not sure what console means, how it works. Can You please briefly explain me how to access console and fire up this file? And also, does the file "Rakefile" need to have any code?

RE: Receiving E-mails via cron - Added by Bernhard Rohloff over 5 years ago

Tomasz Mirecki wrote:

Thank You, I am like Wordpress coding advanced. I am not sure what console means, how it works. Can You please briefly explain me how to access console and fire up this file? And also, does the file "Rakefile" need to have any code?

With console I meant a normal terminal window. But after a bit of googling around I think this is not the usual PATH problem.

The Rakefile should look like the one in the Repository.
As there is some output and I assume you didn't create it this should be fine.

I also found a thread at stackoverflow which covers your error message. It seems that there is something wrong with the installation of ruby or bundler.

I think Redmine has nothing to do with this issue. Are you trying to install Redmine from scratch or is this an old installation you have to maintain?

RE: Receiving E-mails via cron - Added by Martin Denizet (redmine.org team member) over 5 years ago

Hello,
I think I would do something like:

cd /opt/remine/ && bundle exec rake redmine:email:receive_imap RAILS_ENV="production" host=imap.gmail.com port=993 ssl=1 username=programzenweb.pl@gmail.com password=mypassword --trace

Note that I cd to the root of the app, not to the html directory.
Cheers

    (1-10/10)