Exim4Config: Difference between revisions

From Request Tracker Wiki
Jump to navigation Jump to search
(Created page with " Example for exim4 configs: == Debian Exim == The following was tested on Exim 4.94.2 Debian split config. # Install either exim4-daemon-light or exim4-daemon-heavy, depending on feature requirements. exim4-daemon-light is sufficient unless you need database lookup features (MySQL etc.) or content/malware scanning etc. apt-get install exim4-daemon-light === Initial setup === If RT is on a '''dedicated server or VM''', you will probably want to configure Exim in...")
 
No edit summary
 
Line 136: Line 136:
   R: smarthost for bob@example.com
   R: smarthost for bob@example.com
   bob@example.com
   bob@example.com
   <-- bob@support.lonap.net
   <-- bob@rt.example.com
   router = smarthost, transport = remote_smtp_smarthost
   router = smarthost, transport = remote_smtp_smarthost
   host your-mail-server.example.com [x:x:x::x]
   host your-mail-server.example.com [x:x:x::x]

Latest revision as of 02:42, 23 August 2023

Example for exim4 configs:

Debian Exim

The following was tested on Exim 4.94.2 Debian split config.

  1. Install either exim4-daemon-light or exim4-daemon-heavy, depending on feature requirements.

exim4-daemon-light is sufficient unless you need database lookup features (MySQL etc.) or content/malware scanning etc.

apt-get install exim4-daemon-light

Initial setup

If RT is on a dedicated server or VM, you will probably want to configure Exim in smarthost mode.

smarthost mode will send all outgoing email to your mail server. There are some exceptions which you may want to configure.

/etc/exim4/update-exim4.conf.conf example below - set any domains for your RT box, and the mail server name, and then execute update-exim4.conf

# /etc/exim4/update-exim4.conf.conf
#
# Edit this file and /etc/mailname by hand and execute update-exim4.conf
# yourself or use 'dpkg-reconfigure exim4-config'
#
# Please note that this is _not_ a dpkg-conffile and that automatic changes
# to this file might happen. The code handling this will honor your local
# changes, so this is usually fine, but will break local schemes that mess
# around with multiple versions of the file.
#
# update-exim4.conf uses this file to determine variable values to generate
# exim configuration macros for the configuration file.
#
# Most settings found in here do have corresponding questions in the
# Debconf configuration, but not all of them.
#
# This is a Debian specific file

dc_eximconfig_configtype='smarthost'
dc_other_hostnames='rt.example.com:support.example.com'
dc_local_interfaces=
dc_readhost=
dc_relay_domains=
dc_minimaldns='false'
dc_relay_nets=
dc_smarthost='your-mail-server.example.com'
CFILEMODE='644'
dc_use_split_config='true'
dc_hide_mailname='false'
dc_mailname_in_oh='true'
dc_localdelivery='mail_spool'

Macros (Defined in debian-exim config. Allows easy enabling or config of certain features.)

/etc/exim4/conf.d/main/000_localmacros:

REWRITE_LOCAL_DOMAIN = example.com
SYSTEM_ALIASES_PIPE_TRANSPORT = address_pipe
IGNORE_SMTP_LINE_LENGTH_LIMIT = 1
MAIN_TRUSTED_USERS = www-data

Outgoing mail - extra tweaks

1. Optional: Allow exceptions to sending everything to the smarthost, for example some local mailboxes.

The following will deliver mail to bob@rt.example.com, but only if the user bob actually exists, and there is a mailbox file in /var/mail/bob

/etc/exim4/conf.d/router/900_exim4-config_local_user

# /etc/exim4/conf.d/router/900_exim4-config_local_user
#
# This router matches local user mailboxes.
  
local_user:
  debug_print = "R: local_user for $local_part@$domain"
  driver = accept
  domains = +local_domains
  require_files = /var/mail/${local_part}
  check_local_user
  # local_parts = ! root
  transport = LOCAL_DELIVERY
  cannot_route_message = Unknown user

Everything else will get sent to the smarthost, (Even if the user exists, a mailbox file must also exist)

Test with:

 # touch /var/mail/bob && chown bob:bob /var/mail/bob
 # service exim4 restart
 # id bob
 uid=1002(bob) gid=1002(bob) groups=1002(bob),27(sudo)
 # exim -bt bob@rt.example.com
 R: system_aliases for bob@rt.example.com
 R: userforward for bob@rt.example.com
 R: procmail for bob@rt.example.com
 R: maildrop for bob@rt.example.com
 R: lowuid_aliases for bob@rt.example.com (UID 1002)
 R: local_user for bob@rt.example.com
bob@rt.example.com
 router = local_user, transport = mail_spool


2. Optional: Reroute *@rt.example.com to *@example.com

Bear in mind that Exim will be the MTA for everything on the local machine, not just RT. It can be annoying if local processes, (for example cron) send mail to local users where it will either bounce, or sit in /var/mail and never be seen.

To ensure local mail gets delivered to a user's actual mailbox (and save a bit of /etc/aliases hell), the following will deliver any mail for local users to the main domain (and via the smarthost):

# /etc/exim4/conf.d/router/950_exim4-config_local_user_smarthost
# force delivery of user@rt.example.com -> user@example.com:

not_local_user:
  debug_print = "R: not_local_user for $local_part@$domain"
  driver = redirect
  domains = +local_domains
  data = ${local_part}@REWRITE_LOCAL_DOMAIN
  no_verify


Test with:

 # service exim4 restart
 # exim -bt bob@rt.example.com
  R: system_aliases for bob@rt.example.com
  R: userforward for bob@rt.example.com
  R: procmail for bob@rt.example.com
  R: maildrop for bob@rt.example.com
  R: lowuid_aliases for bob@rt.example.com (UID 1002)
  R: local_user for bob@rt.example.com
  R: not_local_user for bob@rt.example.com
  R: smarthost for bob@example.com
  bob@example.com
  <-- bob@rt.example.com
  router = smarthost, transport = remote_smtp_smarthost
  host your-mail-server.example.com [x:x:x::x]
  host your-mail-server.example.com [x.x.x.x]


Incoming mail

For incoming mail to RT, the simplest method is to add the queue aliases to /etc/aliases:

On your mail server (if appropriate):

### RT/Ticketer Addresses:
sales:                  sales@rt.example.com
sales-comment:          sales-comment@rt.example.com
support:                support@rt.example.com
support-comment:        support-comment@rt.example.com
accounts:               accounts@rt.example.com
accounts-comment:       accounts-comment@rt.example.com

On the RT server:

# forwarders for RT queues:

sales: "|/usr/bin/rt-mailgate --queue \"Sales\" --action correspond --url https://rt.example.com/rt"
sales-comment: "|/usr/bin/rt-mailgate --queue \"Sales\" --action comment --url https://rt.example.com/rt"

support: "|/usr/bin/rt-mailgate --queue \"Support\" --action correspond --url https://rt.example.com/rt"
support-comment: "|/usr/bin/rt-mailgate --queue \"Support\" --action comment --url https://rt.example.com/rt"

accounts: "|/usr/bin/rt-mailgate --queue \"Accounts\" --action correspond --url https://rt.example.com/rt"
accounts-comment: "|/usr/bin/rt-mailgate --queue \"Accounts\" --action comment --url https://rt.example.com/rt"