Home > Uncategorized > Redmine by Email Part 1: IMAP polling for incoming issues

Redmine by Email Part 1: IMAP polling for incoming issues

You may come across the need to have a user who is external to your security realm have access to the contents of redmine issues. Since they do not have direct access to your redmine instance, giving them access to the data is a challenge.

There are a few solutions: create a dump using a redmine “issue list to csv” script/plugin, then import the csv to whatever tracking software they use; or just use email.

Email is not good:

Granted you can’t guarantee the security of assets and systems outside of your control; optimally, you would create a “dead drop” with a encrypted file. I believe that this would be easier to secure than Email, since it could at least be audited and access controlled by additional policies. This could be easily automated.

If this wouldn’t work for you, setting up a “two way” conversation about issues over Email is very easy, and if everyone agrees that the data does not need to be super-duper secure (again, system outside of your security realm == no security anyway), then Email is a fine solution.

Setting up a user to be a watcher of a project (for instance) is quite easy in redmine. This will send Emails (by default) using whatever facility you’ve configured in configuration.yml.

Maintaining a high level of security (specifically confidentiality and accountability) is difficult when dealing with Email. In fact, it’s safe to assume there is no confidentiality or accountability (that is unless you use some system that tries to guarantee this).

Okay, let’s do it anyway:

These security caveats aside… Redmine has code that will deal with taking in issues and issue updates/notes via incoming Email. Basically, instead of using the web, API, or some other method to update the issues, you are using Email as the transport. Redmine includes a ruby script that will poll IMAP (and POP, and some other magic as well), parse Emails for specific fields, and updates issues as desired.

The Script:

This script should be run in a cron job as the user who is running your redmine instance (has access to your hosted redmine app, as it uses the redmine rails app as an interface to the redmine DB).

To test, try the form of the following:

sudo -u apache /usr/local/bin/rake -f /var/www/redmine/Rakefile redmine:email:receive_imap RAILS_ENV="production" host=externalimap.com port=993 username=robot@externalimap.com password=robotpassword ssl=SSL folder=redmine

There are a lot more parameters you can opt to use with the poller, so check out the Receiving emails page on redmine.org. Some of these options can make the scope of what can be updated tighter.

Schedule a cron job to poll IMAP

Create a log file for the task itself:

touch /var/log/cronapache.log
chown apache:apache /var/log/cronapache.log

Adjust the crontab file for apache to run the :

crontab -u apache -e

Add the following:


*/5 * * * * /usr/local/bin/rake -f /var/www/redmine/Rakefile --trace redmine:email:receive_imap RAILS_ENV="production" host=smtpserver.com port=993 username=robot@externaldomain.com password=robotpassword ssl=SSL folder=redmine > /var/log/cronapache.log

If you see some errors, then setting up the environment might help you.

Where’s the code?
/var/www/redmine/lib/tasks/email.rake contains the code for parsing the command redmine:email:receive_imap
/var/www/redmine/lib/redmine/imap.rb kicks it raw with Net::IMAP, son; then out to MailHandler.
/var/www/redmine/app/models/mail_handler.rb kicks it over to the DB through some more layers of abstraction.

Continue to part 2 to send email to redmine.

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: