Fetchmail

From Request Tracker Wiki
Revision as of 07:39, 19 March 2013 by 79.228.1.229 (talk)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Using fetchmail to poll POP-boxes for incoming email for RT

Sometimes you don't have enough control over the email system to pipe incoming email directly into a program as it arrives - for instance when you're not the email admin. Using the fetchmail program in daemon mode or called by the cron you can periodically check one or more POP-boxes for incoming email and send them into RT.


First you require a fetchmailrc-file which tells fetchmail all the pop-boxes, for instance in /usr/rt/etc/fetchmailrc


poll pop.example.com    proto pop3:
username rt             password mypw1   mda "/usr/rt/bin/rt-mailgate --url http://rt.example.com --queue General --action correspond"
username rt-comment     password mypw2   mda "/usr/rt/bin/rt-mailgate --url http://rt.example.com --queue General --action comment"
username queue1         password mypw3   mda "/usr/rt/bin/rt-mailgate --url http://rt.example.com --queue queue1  --action correspond"
username queue1-comment password mypw4   mda "/usr/rt/bin/rt-mailgate --url http://rt.example.com --queue queue1  --action comment"
username queue2         password mypw5   mda "/usr/rt/bin/rt-mailgate --url http://rt.example.com --queue queue2  --action correspond"
username queue2-comment password mypw6   mda "/usr/rt/bin/rt-mailgate --url http://rt.example.com --queue queue2  --action comment"


If you use a queue with a blank like 'bug report', you must set the queue name in ' '.


Then you simply need to call fetchmail:


fetchmail -f /usr/rt/etc/fetchmailrc


This can be done on any machine that can reach both the POP-server by POP and the RT-Server by HTTP. I prefer to do it directly on the RT-Server.


--- Back to the Documentation page

Using getmail to poll POP-boxes for incoming email for RT

getmail (http://pyropus.ca/software/getmail/) is similar to fetchmail, but provides a few more features. The most useful one is the abillity to delete email from the inbox you are polling after a set time period. It requires a little extra configuration.


First, install and build getmail from http://pyropus.ca/software/getmail/.


You will need a configuration file for each email you intend to check (so this means two configs for each queue- one for replies and one for comments). An example config is below.


[retriever]
type = SimplePOP3Retriever
server = mail.example.com
port = 110
username = test@example.com
password = password

[destination]
type = MDA_external
path = /path/to/rt-mailgate
user = rtuser
group = rtgroup
arguments = ("--url", "http://rt.example.com", "--queue", "ExampleQueue", "--action", "correspond",)

[options]
read_all = false
delete_after = 8
verbose = 2


Notes:


In destination, user and group must be a user and group on the server that getmail runs on. Getmail will fail to run if you try to run it as root without explicitly allowing it to. As this is a security risk, it recommended you create a user/group for getmail to use. The RT user and group seems to work perfectly.

In destination, an entry must be made for each argument that is separate by a space. If there is only one argument, don't forget the trailing comma.

delete_after tells getmail to delete the email 8 days after seeing it for the first time on the server.

read_all prevents it from reading every mail on the server each time it connects. http://www.profi-fachuebersetzung.de

Create a config for each of your emails (in this example, let us say we have a .examplereplyrc and a .examplecommentrc). After creating these, you should create a shell script as below to run as a cron job.


#!/bin/bash
/usr/bin/getmail --rcfile /path/to/.examplereplyrc --rcfile /path/to/.examplecommentrc


Add this shell script to your crontab to complete your setup.