email2trac on Windows

61 views
Skip to first unread message

Nicole

unread,
Mar 7, 2008, 5:01:45 PM3/7/08
to Trac Users
Google and mailing list results hint at people who have succeeded, but
I have yet to come across a complete solution. I'm determined to get
this to work. Eventually. Someday. Maybe. Oh to be one of you lucky
*nix users.

So, I feel like I have the right components in place -- it's just not
jiving yet. Some background:

Platform: Windows Server 2003
Trac: trac 0.11b variant
Python: Python 2.5
email2trac: email2trac .9.5

Since my trac installation isn't on the same server as Exchange, I'm
using fetchmail to fetch email from the mail server and move it to my
trac server. That works fine. I just can't get email2trac.py to read
them. One email2trac ticket (https://subtrac.sara.nl/oss/email2trac/
ticket/5) hints that a batch file that pipes the messages to the
script might work, but I haven't had success with this. Perhaps I
built email2trac incorrectly? I'll be honest -- building packages
within a Windows environment is new to me so I may have done this
incorrectly despite my best efforts to follow documentation I found
scattered about the internet.

Another possible hangup: Could the email2trac script not have correct
permission to my trac db? How do I ensure that it does?

Really, if any Windows user has solved any piece of this puzzle I
would love to hear it. Maybe together we can create a working
solution?

Thanks!

--Nicole

Mike Henke

unread,
Mar 8, 2008, 2:05:03 PM3/8/08
to Trac Users
Good Luck and hope you succeed, then post an entry how you did it but
this google group sucks.

Matthew Carlson

unread,
Mar 10, 2008, 12:04:04 PM3/10/08
to Trac Users
I've been meaning to put a full how-to together on getting Email2Trac
working in Windows (covering getting email to your server all the way
to putting tickets into Trac), but I haven't had the time. It looks
like there are many people struggling to this.

(Just as a disclaimer, I have hardly any Python experience, so my
changes probably aren't very flexible or cross-platform; I was just
trying to get stuff to work)

Platform: Windows Server 2003
Trac: trac 0.10.3
Python: Python 2.4
email2trac: email2trac 0.10

There are 3 pieces you need to effectively turn emails into Trac
tickets:

1. A way to receive emails on your Trac server
2. A way to process or convert emails into Trac tickets (this would be
the email2trac python script)
3. A way to automate part (2.)

Here's what we use on Windows:

1. We use Windows' built-in SMTP server to deliver mail to our trac
server, but since you have that working, I won't elaborate.

2. Email2Trac isn't very Windows-friendly out of the box. I didn't so
much install it, as I ripped the files I wanted out of the source
tarball. Python code doesn't need to be compiled, so this works just
fine. Extract email2trac.tar.gz. Navigate into the resulting
email2trac-0.x folder and rename email2trac.py.in to email2trac.py and
delete_spam.py.in to delete_spam.py. Now copy email2trac.py,
delete_spam.py, and email2trac.conf to the location where you want to
run the script (I put mine in C:\python24\scripts).

For Email2Trac 0.10, I had to alter the script slightly to run. Edit
email2trac.py with your favorite editor (I use IDLE which comes with
the Windows Python package)
Comment out the syslog import (line 95 in 0.10); change:
import syslog
to
#import syslog
(Note: It looks like this is handled in the latest version of
Email2Trac, 0.13)
Next change the default configfile (line 984 in 0.10); change:
configfile = '@email2trac_conf@'
to
configfile = 'email2trac.conf'

Next, you'll want to edit email2trac.conf. Be sure to configure your
environment with Windows-style paths, and specify the temp directory.
(Used to extract attachments) Also, make sure the temp directory
exists. The top of mine looks like this:
[DEFAULT]
project: C:\trac\[environment]
tmpdir: C:\temp
...
(Note: we only use email2trac with one environment on our server
(despite the fact we run several))
You will likely want to make more changes to the config file to suit
your needs. See https://subtrac.sara.nl/oss/email2trac/wiki/Email2tracConfiguration.

At this point, you should be able to push a single email into a ticket
from the command-line. Type:
cd C:\python24\Scripts (or wherever you put email2trac)
python email2trac.py < [C:\path\to\email.eml] (this depends on Python
being in your PATH)

3. We use Windows' Scheduled Tasks to automate email2trac. This works
in two parts: a batch file to run the script on a set of emails and a
scheduled task to run said batch file at regular intervals.

Create a new batch file in the same folder as your email2trac.py, ours
is C:\python24\Scripts\trac-email.bat. Edit it with notepad, insert
the following:
@echo off

for %%f in (C:\Inetpub\mailroot\Drop\*.eml) do python email2trac.py < %
%f
del C:\Inetpub\mailroot\Drop\*.eml
Now change "C:\Inetpub\mailroot\Drop\" to the location where your
emails are being delivered. You may also have to change "*.eml", if
they have different extensions.

Now go to Start->Control Panel->Scheduled Tasks->Add Scheduled Task.
This will start the Scheduled Task Wizard. Use "Browse..." to select
the batch file you just created as the program you wish to run. Give
the task a name you like, select "Daily". Put 12:00 AM as the start
time and perform "Every Day" with the current date as the start date.
For the user, I had problems using the unprivileged user that runs
tracd so I set myself as the user (definitely not secure; this is an
internal trac). Check "Open advanced properties..." and click
"Finish". The edit task dialog will pop up. Click "Schedule" tab,
then "Advanced...". Check "Repeat task", set "Every:" to 10 minutes
(or your desired interval). Set "Duration:" to 24 hours. Click "OK",
"OK" to close the dialogs. You can now test your task by right-
clicking and selecting "Run". You should see a command-line window
briefly appear.

Hopefully this is helpful to you; I set this up a while ago, so I may
be a little rusty on the important details. And hopefully some better
Windows instructions appear on the email2trac site.

- Matthew Carlson

dy20...@sneakemail.com

unread,
Mar 10, 2008, 2:14:22 PM3/10/08
to trac-...@googlegroups.com
Matthew Carlson matthew.carlson-at-cbfgroup.net |TracMailingList| wrote:
> I've been meaning to put a full how-to together on getting Email2Trac
> working in Windows (covering getting email to your server all the way
> to putting tickets into Trac), but I haven't had the time. It looks
> like there are many people struggling to this.

This would be *very* useful.

> ...


>
> 1. We use Windows' built-in SMTP server to deliver mail to our trac
> server, but since you have that working, I won't elaborate.

Please do elaborate. We're running trac on the Windows server 2003 machine, and not being very savvy at Windows server admin stuff, I struggled with this.

Thanks for the rest of your instructions.

Don

Matthew Carlson

unread,
Mar 11, 2008, 3:01:59 PM3/11/08
to Trac Users

On Mar 10, 1:14 pm, dy20lq...@sneakemail.com wrote:
>
> > 1. We use Windows' built-in SMTP server to deliver mail to our trac
> > server, but since you have that working, I won't elaborate.
>
> Please do elaborate. We're running trac on the Windows server 2003 machine, and not being very savvy at Windows server admin stuff, I struggled with this.
>

Ok, so from above, piece #1 is:

1. A way to receive emails on your Trac server

When I setup email2trac, I thought that this step was going to be the
most difficult (mostly because I have no experience with email servers/
services). Surprisingly, it is actually the easiest step. The trick
is to install the SMTP server, but not the POP server, so that emails
are received and left as files in the "drop" folder. (This is the way
an email server hands off email between the two services) In a way,
email2trac performs the distribution functions normally handled by
POP.

Install the SMTP service via Windows Components. Open Add/Remove
Programs (Start->Control Panel->Add or Remove Programs) Click "Add/
Remove Windows Components" in the left-hand bar. Use the "Details..."
button to drill-in to Application Server->Internet Information
Services (IIS)->SMTP Service. Check the box next to SMTP Service,
click "OK", "OK", "Next", "Finish".

I don't remember if I had to configure anything for SMTP (If I did, it
wasn't much). You find configuration at Start->Control Panel-
>Admistrative Tools->Internet Information Services (IIS) Manager. I
have "Default SMTP Virtual Server" listed, with a Domain Name of "trac-
server.domain.com" with Type "Local (Default)". I believe the
installation automaticly creates the drop folder at C:\Inetpub\mailroot
\Drop. You can see that my email2trac batch script picks up .eml
files from that location.

To actually get emails to the server, you have to use the address
"anyt...@trac-server.domain.com". Your exchange or other mail server
should automaticly forward the emails to the server. If you want to
use a different form, you will likely have to configure your mail
server to forward the mail. The name before the @ can be anything;
POP service usually uses this, SMTP and email2trac ignore it. A
possible enhancement to email2trac would be to use the address to
identify the destination environment for the ticket.

Again, this was a while ago, so I may have missed something in the
details.

- Matthew Carlson

Dimitri Maziuk

unread,
Mar 11, 2008, 3:59:33 PM3/11/08
to trac-...@googlegroups.com, Matthew Carlson
On Tuesday 11 March 2008 14:01:59 Matthew Carlson wrote:
... The name before the @ can be anything;

> POP service usually uses this, SMTP and email2trac ignore it. A
> possible enhancement to email2trac would be to use the address to
> identify the destination environment for the ticket.

Just because microshaft ignores it, doesn't mean it's yours to do with as you
will.

Proper SMTP implementations look for it in aliases and users databases and
bounce mail to unknown users. You can use e-mail aliases for different trac
environments, but you don't need any modifications to email2trac -- all you
need is a proper smtp server.

(Your aliases file would look like
someproject: |"/usr/bin/email2trac --project=someproject"
otherproject: |"/usr/bin/email2trac --project=otherproject"
etc.)
(Note also that with message delivery directly to program, your tickets get
updated right away, not after scheduled task decides to kick in.)

Back when I did winders we used something called wingate whose built-in smtp
server could do that.

Dima
--
Dimitri Maziuk
Programmer/sysadmin
BioMagResBank, UW-Madison -- http://www.bmrb.wisc.edu

Mike Henke

unread,
Mar 11, 2008, 5:02:46 PM3/11/08
to Trac Users
Typical trac "genius" reponse, snooty and condescending

dy20...@sneakemail.com

unread,
Mar 11, 2008, 8:36:31 PM3/11/08
to trac-...@googlegroups.com
Matthew Carlson matthew.carlson-at-cbfgroup.net |TracMailingList| wrote:
>
> 1. A way to receive emails on your Trac server
>
> ... snipped explanation of receiving email on the Trac server ...

I appreciate your detailed explanation. I don't think this will work for us, since we run trac on the same computer as our Exchange server (it's a small company, small trac, small email, so this is not a performance problem). I can't figure out how to make Exchange server drop an email into a folder. Do you have any insight with this?

Thanks.

Don

Nicole

unread,
Mar 12, 2008, 1:43:02 PM3/12/08
to Trac Users
Thanks, Matthew, for your detailed response. It's amazing what a
couple edits to the email2trac.py script can do! I'm happy to say
that I've now got it all working smashingly.

A bit about my working solution:

1. Fetchmail -- Retrieves email from the Exchange server. I have it
set up to automatically feed retrieved messages to the script so I
don't need an additional script to do this. At some point I might
want to change this piece of the equation to get rid of the overhead
of the Cygwin component, but it's working and I like having to do a
little Unix-y work. Relevant .fetchmailrc file:

poll mail.domain.com with proto IMAP, auth ntlm user "tr...@domain.com"
with password "xxx" is trac here options keep
mda "C:/python25/python.exe C:/projects/email2trac/email2trac.py"

2. email2trac script -- As can be seen in the above .fetchmailrc file,
I put my script and related files in the path C:/projects/email2trac.
I made the changes to email2trac.py that Matthew mentions along with a
couple changes specific to my solution.
* Config file variable -- Since I'm calling the script from
fetchmail, I needed to specify the full path to the config file in the
email2trac.py script, i.e. C:/projects/email2trac/email2trac.conf
* Signature stripping -- I found that the signature stripping done
in the script when the strip_signature config variable was set didn't
work correctly for the format of our emails so I made a slight edit to
the script. In the section of the script that defines useful mail
constants (around line 141), I added the variable
self.get_signature_match = '---'. Then in the strip_signature method
(around line 728) I replaced the line "if line == '-- ':" with "if
line.startswith(self.get_signature_match):". This resulted in the
successful stripping of most signatures as well as old original
message info I didn't want to get added on each response.

Note: See https://subtrac.sara.nl/oss/email2trac/wiki/Email2tracConfiguration
for complete configuration instructions.

3. email2trac.conf -- Matthew covered this, but might as well mention
it again along with a caveat I found related to using email2trac with
trac 0.11. So, important config variables:
[DEFAULT]
project: C:\projects\trac\environmentname
tmpdir: C:\tmp
ticket_update: 1
strip_signature: 1
python_egg_cache: C:\Python25\Scripts
trac_version: 0.11

Obviously, if you don't wish to strip signatures, you would set that
to 0. The trac_version variable is important if you're running trac .
11 so that you don't receive an error like "str object is not
callable". See https://subtrac.sara.nl/oss/email2trac/ticket/34 for
more information about the background of this one.

4. Making it all work together -- I created a simple batch file that
is run by Scheduled Tasks. All it does is run fetchmail.

C:\cygwin\bin\fetchmail -v --fetchmailrc C:/cygwin/path/to/fetchmailrc
--logfile c:/projects/email2trac/fetchmail.log

Thanks everyone for your responses and hopefully this can help someone
in the future!

--Nicole




Mike Henke

unread,
Mar 12, 2008, 4:57:25 PM3/12/08
to Trac Users
You should upload your solution to http://trac.edgewall.org/wiki/Email2tracOnWindows?action=edit&template=

On Mar 12, 12:43 pm, Nicole <nicole.s...@gmail.com> wrote:
> Thanks, Matthew, for your detailed response.  It's amazing what a
> couple edits to the email2trac.py script can do!  I'm happy to say
> that I've now got it all working smashingly.
>
> A bit about my working solution:
>
> 1. Fetchmail -- Retrieves email from the Exchange server.  I have it
> set up to automatically feed retrieved messages to the script so I
> don't need an additional script to do this.  At some point I might
> want to change this piece of the equation to get rid of the overhead
> of the Cygwin component, but it's working and I like having to do a
> little Unix-y work.  Relevant .fetchmailrc file:
>
> poll mail.domain.com with proto IMAP, auth ntlm user "t...@domain.com"
> with password "xxx" is trac here options keep
> mda "C:/python25/python.exe C:/projects/email2trac/email2trac.py"
>
> 2. email2trac script -- As can be seen in the above .fetchmailrc file,
> I put my script and related files in the path C:/projects/email2trac.
> I made the changes to email2trac.py that Matthew mentions along with a
> couple changes specific to my solution.
>     * Config file variable -- Since I'm calling the script from
> fetchmail, I needed to specify the full path to the config file in the
> email2trac.py script, i.e. C:/projects/email2trac/email2trac.conf
>     * Signature stripping -- I found that the signature stripping done
> in the script when the strip_signature config variable was set didn't
> work correctly for the format of our emails so I made a slight edit to
> the script.  In the section of the script that defines useful mail
> constants (around line 141), I added the variable
> self.get_signature_match = '---'.  Then in the strip_signature method
> (around line 728) I replaced the line "if line == '-- ':" with "if
> line.startswith(self.get_signature_match):".  This resulted in the
> successful stripping of most signatures as well as old original
> message info I didn't want to get added on each response.
>
> Note: Seehttps://subtrac.sara.nl/oss/email2trac/wiki/Email2tracConfiguration

Nicole

unread,
Mar 21, 2008, 7:09:35 PM3/21/08
to Trac Users
I thought it seemed most relevant to add it to the email2trac website,
so I have. I'm considering it a "work in progress" as of now.

See: https://subtrac.sara.nl/oss/email2trac/wiki/Email2tracOnWindows

Matthew -- If you have time, could you look at the pieces specific to
using the built-in SMTP server to make sure it's accurate?

Thanks everyone!

--Nicole


On Mar 12, 2:57 pm, Mike Henke <henkem...@gmail.com> wrote:
> You should upload your solution tohttp://trac.edgewall.org/wiki/Email2tracOnWindows?action=edit&template=

Nicole

unread,
Mar 23, 2008, 2:00:25 AM3/23/08
to Trac Users

Matthew Carlson

unread,
Mar 24, 2008, 10:12:34 PM3/24/08
to Trac Users
I have updated the documentation at
https://subtrac.sara.nl/oss/email2trac/wiki/Email2tracInstallation/Windows.
A summary of my posts can be found at my blog (shameless plug!)
http://functionalelegant.blogspot.com/2008/03/email2trac-on-windows.html.

- Matthew Carlson

On Mar 23, 1:00 am, Nicole <nicole.s...@gmail.com> wrote:
> The page has moved tohttps://subtrac.sara.nl/oss/email2trac/wiki/Email2tracInstallation/Wi...
> > > > --Nicole- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages