Configure Request Tracker to Fetch Email Requests from Mail Box

In this tutorial, you will learn how to configure Request Tracker to fetch email requests from mail box. Any support request is sent to a mail box such as [email protected]. In order for the application to display/show these requests on its web dashboard, you need to configure it to be able to fetch the mails sent to the support mail box.

Configure Request Tracker to Fetch Email Requests from Mail Box

There are different applications you can configure Request tracker to use to fetch email requests from the mail box. These include fetchmail, mbox2rt and pop3mailgate. We will however be using fetchmail in this guide.

Configure RT to Fetch Mails using Fetchmail

To begin with, install fetchmail program on your Request Tracker server.

Ubuntu/Debian and Similar derivative;

apt install fetchmail

CentOS/Rocky/Oracle/RHEL based derivatives;

yum install fetchmail

Consult respective Linux distro documentation on how to install fetchmail.

Once the installation is done, you need to configure fetchmail to retrive email from a mail box.

Thus, create a configuration file for fetchmail, /etc/fetchmailrc

vim /etc/fetchmailrc

Here is our sample configuration. Note that we are using Gmail as our mail server. Hence, make appropriate changes.

set daemon 60
set no syslog
set logfile "/var/log/fetchmail/fetchmail.log"
set no bouncemail
defaults:
  antispam -1
  batchlimit 100

poll imap.gmail.com
  protocol IMAP
  user "[email protected]"
  password "passW)RD"
  ssl
  no fetchall
  no rewrite
  keep
  mda "/opt/rt5/bin/rt-mailgate --url https://rt5.itnixpro.com --no-verify-ssl --queue General --action correspond --debug"

Below are the Fetchmail keywords/options summary.

KeywordOptModeFunction
set daemon-dSet a background poll interval in seconds.
set postmasterGive the name of the last-resort mail recipient (default: user running fetchmail, “postmaster” if run by the root user)
set bouncemailDirect error mail to the sender (default)
set no bouncemailDirect error mail to the local postmaster (as per the ‘postmaster’ global option above).
set no spambounceDo not bounce spam-blocked mail (default).
set spambounceBounce blocked spam-blocked mail (as per the ‘antispam’ user option) back to the destination as indicated by the ‘bouncemail’ global option. Warning: Do not use this to bounce spam back to the sender – most spam is sent with false sender address and thus this option hurts innocent bystanders.
set no softbounceDelete permanently undeliverable mail. It is recommended to use this option if the configuration has been thoroughly tested.
set softbounceKeep permanently undeliverable mail as though a temporary error had occurred (default).
set logfile-LName of a file to append error and status messages to. Only effective in daemon mode and if fetchmail detaches. If effective, overrides set syslog.
set pidfile-pName of the PID file.
set idfile-iName of the file to store UID lists in.
set syslogDo error logging through syslog(3). May be overridden by set logfile.
set no syslogTurn off error logging through syslog(3). (default)
set propertiesString value that is ignored by fetchmail (may be used by extension scripts).

Here are the legal server options:

KeywordOptModeFunction
viaSpecify DNS name of mail server, overriding poll name
proto[col]-pSpecify protocol (case insensitive): POP2, POP3, IMAP, APOP, KPOP
local[domains]mSpecify domain(s) to be regarded as local
portSpecify TCP/IP service port (obsolete, use ‘service’ instead).
service-PSpecify service name (a numeric value is also allowed and considered a TCP/IP port number).
auth[enticate]Set authentication type (default ‘any’)
timeout-tServer inactivity timeout in seconds (default 300)
envelope-EmSpecify envelope-address header name
no envelopemDisable looking for envelope address
qvirtual-QmQmail virtual domain prefix to remove from user name
akamSpecify alternate DNS names of mail server
interface-Ispecify IP interface(s) that must be up for server poll to take place
monitor-MSpecify IP address to monitor for activity
pluginSpecify command through which to make server connections.
plugoutSpecify command through which to make listener connections.
dnsmEnable DNS lookup for multidrop (default)
no dnsmDisable DNS lookup for multidrop
checkaliasmDo comparison by IP address for multidrop
no checkaliasmDo comparison by name for multidrop (default)
uidl-UForce POP3 to use client-side UIDLs (recommended)
no uidlTurn off POP3 use of client-side UIDLs (default)
intervalOnly check this site every N poll cycles; N is a numeric argument.
tracepollsAdd poll tracing information to the Received header
principalSet Kerberos principal (only useful with IMAP and kerberos)
esmtpnameSet name for RFC2554 authentication to the ESMTP server.
esmtppasswordSet password for RFC2554 authentication to the ESMTP server.
bad-headerHow to treat messages with a bad header. Can be reject (default) or accept.

Here are the legal user descriptions and options:

KeywordOptModeFunction
user[name]-uThis is the user description and must come first after server description and after possible server options, and before user options.It sets the remote user name if by itself or followed by ‘there’, or the local user name if followed by ‘here’.
isConnect local and remote user names
toConnect local and remote user names
pass[word]Specify remote account password
sslConnect to server over the specified base protocol using SSL encryption
sslcertSpecify file for client side public SSL certificate
sslcertckEnable strict certificate checking and abort connection on failure. Default only since fetchmail v6.4.0.
no sslcertckDisable strict certificate checking and permit connections to continue on failed verification. Discouraged. Should only be used together with sslfingerprint.
sslcertfileSpecify file with trusted CA certificates
sslcertpathSpecify c_rehash-ed directory with trusted CA certificates.
sslfingerprint<HASH>Specify the expected server certificate finger print from an MD5 hash. Fetchmail will disconnect and log an error if it does not match.
sslkeySpecify file for client side private SSL key
sslprotoForce ssl protocol for connection
folder-rSpecify remote folder to query
smtphost-SSpecify smtp host(s) to forward to
fetchdomainsmSpecify domains for which mail should be fetched
smtpaddress-DSpecify the domain to be put in RCPT TO lines
smtpnameSpecify the user and domain to be put in RCPT TO lines
antispam-ZSpecify what SMTP returns are interpreted as spam-policy blocks
mda-mSpecify MDA for local delivery
bsmtpSpecify BSMTP batch file to append to
preconnectCommand to be executed before each connection
postconnectCommand to be executed after each connection
keep-kDo not delete seen messages from server (for POP3, uidl is recommended)
flush-FFlush all seen messages before querying (DANGEROUS)
limitflushFlush all oversized messages before querying
fetchall-aFetch all messages whether seen or not
rewriteRewrite destination addresses for reply (default)
stripcrStrip carriage returns from ends of lines
forcecrForce carriage returns at ends of lines
pass8bitsForce BODY=8BITMIME to ESMTP listener
dropstatusStrip Status and X -Mozilla-Status lines out of incoming mail
dropdeliveredStrip Delivered-To lines out of incoming mail
mimedecodeConvert q uoted-printable to 8-bit in MIME messages
idleIdle waiting for new messages after each poll (IMAP only)
no keep-KDelete seen messages from server (default)
no flushDo not flush all seen messages before querying (default)
no fetchallRetrieve only new messages (default)
no rewriteDo not rewrite headers
no stripcrDo not strip carriage returns (default)
no forcecrDo not force carriage returns at EOL (default)
no pass8bitsDo not force BODY=8BITMIME to ESMTP listener (default)
no dropstatusDo not drop Status headers (default)
no dropdeliveredDo not drop Delivered-To headers (default)
no mimedecodeDo not convert q uoted-printable to 8-bit in MIME messages (default)
no idleDo not idle waiting for new messages after each poll (IMAP only)
limit-lSet message size limit
warnings-wSet message size warning interval
batchlimit-bMax # messages to forward in single connect
fetchlimit-BMax # messages to fetch in single connect
fetchsizelimitMax # message sizes to fetch in single transaction
fastuidlUse binary search for first unseen message (POP3 only)
expunge-ePerform an expunge on every #th message (IMAP and POP3 only)
propertiesString value is ignored by fetchmail (may be used by extension scripts)

Update the permissions and ownership of the fetchmailrc configuration file;

chmod 0600 /etc/fetchmailrc
chown fetchmail: /etc/fetchmailrc

Create the log file directory specified for the Fetchmail by the set logfile "/var/log/fetchmail/fetchmail.log";

mkdir /var/log/fetchmail

Next, create the log file;

touch /var/log/fetchmail/fetchmail.log

Set the ownership to fetchmail;

chown -R fetchmail: /var/log/fetchmail

Ensure the log file is rotated;

sed -i '/messages/a /var/log/fetchmail/fetchmail.log' /etc/logrotate.d/rsyslog

Running Fetchmail Service as Daemon

We will run Fetchmail as a systemd service in this setup.

Thus, edit the defaults configuration file and enable it to run as daemon;

vim /etc/default/fetchmail
START_DAEMON=yes

Similarly, enable some verbosity to help in troubleshooting;

OPTIONS="-vv"

Save and exit the file.

Start Fetchmail service;

systemctl enable --now fetchmail

Check the logs;

tail -f /var/log/fetchmail/fetchmail.log

When a user who has rights to create a ticket on RT sends an email to RT support email address, it should now be able to be displayed on the Request tracker web user interface under the default queue, General, as specified by the mda command in the fetchmailrc configuration file.

fetchmail: IMAP< A0007 OK Success
fetchmail: message [email protected]@imap.gmail.com:2 was not the expected length (4751 actual != 5102 expected)
/opt/rt5/bin/rt-mailgate: temp file is '/tmp/1WC_sA3hkF/SG1bWJ28nd'
/opt/rt5/bin/rt-mailgate: connecting to http://rt5.itnixpro.com/REST/1.0/NoAuth/mail-gateway
ok

Ticket: 5
Queue: General
Owner: Nobody
Status: new
Subject: Fetchmail Ticket Confirmation
Requestor: [email protected]

fetchmail:  not flushed
fetchmail: IMAP> A0008 STORE 2 +FLAGS (\Seen)
fetchmail: IMAP< * 2 FETCH (FLAGS (\Seen))
fetchmail: IMAP< A0008 OK Success
fetchmail: selecting or re-polling default folder
fetchmail: 0 messages waiting after re-poll
fetchmail: IMAP> A0009 LOGOUT
fetchmail: IMAP< * BYE LOGOUT Requested
fetchmail: IMAP< A0009 OK 73 good day (Success)
fetchmail: 6.4.2 querying imap.gmail.com (protocol IMAP) at Mon Oct  3 21:07:18 2022: poll completed
fetchmail: New UID list from imap.gmail.com:
 
fetchmail: not swapping UID lists, no UIDs seen this query
fetchmail: sleeping at Mon Oct  3 21:07:18 2022 for 60 seconds

Similarly, tail RT logs just in case there is an issue;

tail -f /var/log/rt5/rt5.itnixpro.com.log

And that concludes our guide on how to configure Request Tracker to fetch email requests from mail box.

Other Tutorials

Reset Default Root Password on Request Tracker (RT)

Install Request Tracker (RT) on Ubuntu 20.04/Ubuntu 22.04

Founder of itnixpro.com|Linux Engineer|Author at Itnixpro.com

Leave a Comment