08 December 2011

Setting up Exim4 to allow Tagging: user+tag@domain.com

Email Tagging is a super-handy feature in GMail and other services, but if you run your own mail server on Exim4 this should be possible for you also.  Let me show you how!

Briefly, email address tagging (or "sub-addressing") means that if user@domain.com is a valid email address, then we can tag it with +anything (well, almost anything) and still have it be delivered to the user@domain.com address which allows for easy sorting and searches or to see who is selling your information:
  user+amazon@domain.com
  user+petition@domain.com
  user-senator@domain.com

To do this we need to first have your Exim4 server working properly and ports forwarded in the firewall or whatever you need to make Email flow; this is beyond this HowTo.  Then you need to know if you use Exim4's config split into smaller files or if the config is done in one large file (or make the changes in both, I suppose).  On Debian we can find this out by configuring Exim4 (or not changing the working settings if they work already) :
root-shell#  dpkg-reconfigure exim4-config
  internet site; mail is sent and received directly using SMTP <Ok>
  System mail name: domain.com <Ok>
  IP-addresses to listen on for incoming SMTP connections: _________ <Ok>
  Other destinations for which mail is accepted: <Ok>
  Domains to relay mail for: <Ok>
  Machines to relay mail for: <Ok>
  Keep number of DNS-queries minimal (Dial-on-Demand)? <No>
  Delivery method for local mail:  (You decide but an mbox file is a single point of failure) <Ok>
  Split configuration into small files?  <No>

Exim4 will restart with your config changes.  Now we're going to add a few lines to the config.

If you DO have this split into smaller configs, open the files listed below (Debian 6; your files may be different) and add the lines in bold:

root-shell#  vim /etc/exim4/conf.d/router/600_exim4-config_userforward
userforward:
debug_print = "R: userforward for $local_part@$domain"
driver = redirect
local_part_suffix = -* : +*

local_part_suffix_optional

domains = +local_domains
check_local_user
file = $home/.forward
require_files = $local_part:$home/.forward
no_verify
no_expn
check_ancestor
allow_filter
forbid_smtp_code = true
directory_transport = address_directory
file_transport = address_file
pipe_transport = address_pipe
reply_transport = address_reply
skip_syntax_errors
syntax_errors_to = real-$local_part@$domain
syntax_errors_text = \
This is an automatically generated message. An error has\n\
been found in your .forward file. Details of the error are\n\
reported below. While this error persists, you will receive\n\
a copy of this message for every message that is addressed\n\
to you. If your .forward file is a filter file, or if it is\n\
a non-filter file containing no valid forwarding addresses,\n\
a copy of each incoming message will be put in your normal\n\
mailbox. If a non-filter file contains at least one valid\n\
forwarding address, forwarding to the valid addresses will\n\
happen, and those will be the only deliveries that occur.




And this one:
root-shell#  vim /etc/exim4/conf.d/router/900_exim4-config_local_user
local_user:
debug_print = "R: local_user for $local_part@$domain"
driver = accept
local_part_suffix = -* : +*

local_part_suffix_optional
domains = +local_domains
check_local_user
local_parts = ! root
transport = LOCAL_DELIVERY
cannot_route_message = Unknown user







If you're NOT using split-file, edit this single file and find these two sections and edit them to add the parts in bold:

userforward:
debug_print = "R: userforward for $local_part@$domain"
driver = redirect
local_part_suffix = -* : +*
local_part_suffix_optional
domains = +local_domains ....
....
....
local_user:
debug_print = "R: local_user for $local_part@$domain"
driver = accept
local_part_suffix = -* : +*
local_part_suffix_optional
domains = +local_domains
check_local_user
...
...
...

Rebuild your config:

root-shell#  update-exim4.conf

Find your config file and look in there to see if these changes made it:


root-shell#  exim -bV
Exim version 4.69 #1 built 30-Jan-2011 20:48:20Copyright (c) University of Cambridge 2006Berkeley DB: Berkeley DB 4.6.21: (September 27, 2007)Support for: crypteq iconv() IPv6 GnuTLS move_frozen_messagesLookups: lsearch wildlsearch nwildlsearch iplsearch cdb dbm dbmnz dnsdb dsearch nis nis0 passwdAuthenticators: cram_md5 plaintextRouters: accept dnslookup ipliteral manualroute queryprogram redirectTransports: appendfile/maildir/mailstore autoreply lmtp pipe smtpFixed never_users: 0Size of off_t: 8
Configuration file is /var/lib/exim4/config.autogenerated


Assuming the config file looks right, restart Exim4 and try your emailing now with a +sometag
root-shell#  /etc/init.d/exim4 restart

Note that in our two lines that we added:
local_part_suffix = -* : +*
local_part_suffix_optional

 
the first line has a minus and a star, colon, plus and a star.  The colon separates the options and we're saying that a minus-anything or plus-anything on an address is an acceptable tag.  We could specify this more with this instead:
local_part_suffix = -beta
local_part_suffix_optional


to accept only user-beta@domain.com if that is what we wanted.

0 comments: