Scheduling Rake for Redmine to Receive Email (rake redmine:email:receive_imap)

#Crontab runs this every ten minutes (root)
*/10 * * * * /root/scripts/redmine-rake.sh > /tmp/redmine-email.log 2>&1

#this is the script
One of the recent projects I gave myself was setting up redmine for project management. I’ve found it to be a great project management system and since I’ve been looking for alternatives to Basecamp-because of the monthly extortion fees-this one stood out. I’ll leave a review for another post but it’s the best tool I’ve found, much better than trac, and since I’m really familiar with it (Shane and Peter, whom I’ve been working a lot with lately, use the tool) it was an easy choice.

The choice may have been easy but the installation and parts of the setup were not.

One issue was getting a simple cron job to run the rake task of fetching email.

I was continually getting errors like:

/usr/bin/rake:9:in 'require': no such file to load -- rubygems (LoadError)
       from /usr/bin/rake:9

Turns out when rake is run in cron, the .bash_profile file is not processed, so you must include the environment initialization in your cron script. I should have figured this out yesterday, instead I spent countless hours figuring this out.

Here is the cron I’m using:

#Crontab runs this every ten minutes (root)
*/10 * * * * /root/scripts/redmine-rake.sh > /tmp/redmine-email.log 2>&1

This is the bash script I’m using:

#!/bin/bash
export PATH=$PATH:/usr/local/rubygems/bin:/usr/local/rubygems/gems/bin
export RUBYLIB=/usr/local/rubygems/lib
export GEM_HOME=/usr/local/rubygems/gems
cd /var/www/vhosts/scatter3d.com/subdomains/redmine/httpdocs
RAILS_ENV="production" rake redmine:email:receive_imap port=993 host=imap.gmail.com username=redmine@domain.com password=redmine42 ssl=1
cd /var/www/[FULL PATH]/subdomains/redmine/httpdocs
RAILS_ENV="production" /usr/local/rubygems/gems/bin/rake redmine:email:receive_imap host=imap.gmail.com username=[username] password=[password] ssl=YES port=993

For those interested those settings are for gmail apps, so you’ll need to change them accordingly.

  • Jaroslav K.
    Thank you for great tutorial.
    Have one problem: I can add comments (notes) using mail to issues created via portal (via web) but cannot create new issue. Mails in mailbox (IMAP) are marked as read, but no new issue created after shell execution.

    Thank you very much for you time and answer.
  • Jaroslav K.
    Hello,
    I have figured the solution: there must be "project=[project identificator]", not "project=[project name]".

    But despite that, I cannot create new issue from not authenticated user :/ I make project public but that not helped.
blog comments powered by Disqus