Basic exim configuration - redirect all out-bound emails to local address
I have exim running on a development server.
It's currently not able to deliver mail anywhere other than locally. This is fine though - I don't want to be able to accidentally spam our entire userbase. But it does make it difficult to see if the email system is working.
So, I want to capture all emails that exim tries to send (these emails are generated by a web-based CRM system on the same server), and store them in a shared mailbox (that I plan to make accessible to all developers via Dovecot/IMAP)
i.e. I want to redirect all outbound email to a local mbox.
Is this possible? I'm a complete exim beginner, and struggling with it.
Solution 1:
Sure you can. You must configure a redirect
router, as in:
catch_all_outgoing:
driver = redirect
data = admin [at] email
unseen
N.B. The unseen
means "go ahead with other routers". If you want ONLY to trap email and not to forward it to the intended recipient, just remove it.
Take a look at the exim documentation, it's full of examples like this.
Solution 2:
A simple solution to this is to specify a new router and a corresponding transport. First, we configure exim to listen to a different port for emails which are to be delivered to the single mailbox. This example uses port 2525
on 127.0.0.1
, so make sure that your CRM is configured to send messages via SMTP on this port when running the tests. If the mail server is also being used for other purposes, you will need to add this address and port to the existing local_interfaces
configuration.
local_interfaces = <; 127.0.0.1.2525
Next we need a router which we call development
in the example below. We specify a condition that messages received via SMTP on port 2525
should be accepted by this router and passed to the transport called single_box.
This should be placed immediately after the exim configuration section labelled begin routers
begin routers
development:
debug_print = "R: client_development for $local_part@$domain"
driver = accept
condition = ${if eq {$interface_port}{2525} {1}{0}}
transport = single_box
no_more
Next we need to define a transport, which will take the routed messages and save them somewhere. We'll keep things simple and save these in a single mailbox. The transport configuration can be placed anywhere in the section which starts begin transports
single_box:
debug_print = "T: single_box for $local_part@$domain"
driver = appendfile
group = Debian-exim
mode = 0660
mode_fail_narrower = false
delivery_date_add
envelope_to_add = true
return_path_add = true
directory = /home/mailspace/mailboxes/development/Maildir/
maildir_format
create_directory = true
This example creates a Maildir-format mailbox in the corresponding directory; make sure your you change this location to something suitable for your server. Also make sure your change the group name that used by the mailserver; the example here assumes a standard Debian system. Maildir is a common format where email messages are saved as individual files. These can be easily examined using a text editor and the Maildir format is supported by dovecot and courier if you want to make the mailbox available using IMAP.