Fetchmail

From Request Tracker Wiki
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 lists for 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 space, like 'bug report', you must contain the queue name in single quotes. Do not use double quotes (e.g. "bug report").

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. You may also

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 ability 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 mailbox you intend to check. For example, If you use one mailbox for replies, and another mailbox for comments, you will need two configuration files. 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 the [destination] section, 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 will work, as long as it is given adequate permissions.
  • Each entry in the arguments list must be separated by a space, and must end with a 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.

After creating configuration files for each of your RT queues, you must also create a shell script, as below, to retrieve mail as a cron job. Add this script to your crontab to complete your setup.

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

--- Back to the Documentation page