Difference between revisions of "Fetchmail"

From Request Tracker Wiki
Jump to navigation Jump to search
m (22 revisions imported)
 
(Cleaned up formatting)
Line 1: Line 1:
==Using fetchmail to poll POP-boxes for incoming email for RT==
==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:
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.
<pre>poll pop.example.com    proto pop3:
 
 
 
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            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 rt-comment    password mypw2  mda "/usr/rt/bin/rt-mailgate --url http://rt.example.com --queue General --action comment"
Line 16: Line 10:
  username queue1-comment password mypw4  mda "/usr/rt/bin/rt-mailgate --url http://rt.example.com --queue queue1  --action comment"
  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        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"
  username queue2-comment password mypw6  mda "/usr/rt/bin/rt-mailgate --url http://rt.example.com --queue queue2  --action comment"</pre>
 
 


If you use a queue with a blank like 'bug report', you must set the queue name in ' '.
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:
Then you simply need to call fetchmail:


 
<pre>fetchmail -f /usr/rt/etc/fetchmailrc</pre>
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.
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==
==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.
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/.
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.


 
<pre>[retriever]
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.
type = SimplePOP3Retriever
 
server = mail.example.com
 
port = 110
[retriever]
username = test@example.com
type = SimplePOP3Retriever
password = password
server = mail.example.com
port = 110
username = test@example.com
password = password
   
   
[destination]
[destination]
type = MDA_external
type = MDA_external
path = /path/to/rt-mailgate
path = /path/to/rt-mailgate
user = rtuser
user = rtuser
group = rtgroup
group = rtgroup
arguments = ("--url", "http://rt.example.com", "--queue", "ExampleQueue", "--action", "correspond",)
arguments = ("--url", "http://rt.example.com", "--queue", "ExampleQueue", "--action", "correspond",)
   
   
[options]
[options]
read_all = false
read_all = false
delete_after = 8
delete_after = 8
verbose = 2
verbose = 2</pre>
 
 


Notes:
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.
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.


*
* '''delete_after''' tells getmail to delete the email 8 days after seeing it for the first time on the server.
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.


*
* '''read_all''' prevents it from reading every mail on the server each time it connects.
delete_after tells getmail to delete the email 8 days after seeing it for the first time on the server.


*
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.
read_all prevents it from reading every mail on the server each time it connects.


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




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.
--- Back to the [[Documentation]] page
 
 
#!/bin/bash
/usr/bin/getmail --rcfile /path/to/.examplereplyrc --rcfile /path/to/.examplecommentrc
 
 
 
Add this shell script to your crontab to complete your setup.

Revision as of 18:56, 7 September 2016

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 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.

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