vexim / vexim2

Virtual Exim 2
Other
71 stars 47 forks source link

outgoing IP per domain #245

Open runout-at opened 6 years ago

runout-at commented 6 years ago

this is still missing the part for the webUI. But i want to discuss if this is going in the right direction.

30

Udera commented 6 years ago

You are planning that you can put a list of IPs? Or how do you manage ipv4 and ipv6?

runout-at commented 6 years ago

The easiest solution would be to have just one additional field in the 'domains' table and put a semicolon separated list of IPs there. This way we can have mix of IPv4 and IPv6 in this field and can use it 'as is' in the transport like interface = <; OUTGOING_IP_ADDRESSES

Maybe the WebUI could be more complex if we like to check/sanitize the values on input or split ddresses in separate fields - but to me, one field would be enough. I wouldn't do checks on every mail in exim. One could monitor the validity of the addresses with a cron job.

runout-at commented 6 years ago

This is on my production servers for 2 weeks without issues, IPv4/v6 dual stack.

The only part missing here is the transports. For now i add following to the original Debian transport files but i'm not sure what is the best way to integrate this in vexim:

.ifdef OUTGOING_IP_ADDRESSES
  interface = <; OUTGOING_IP_ADDRESSES
.endif

added to following files: /etc/exim4/conf.d/transport/30_exim4-config_remote_smtp /etc/exim4/conf.d/transport/30_exim4-config_remote_smtp_smarthost

Udera commented 6 years ago

Let's wait for the 2.4 milestone when the new webinterface is planned. Though it seems very far away.

runout-at commented 6 years ago

i think that we can have the actual changes earlier and do the webUI later.

Having different IPs per domain is a good feature. Besides from IPv6 it makes it easier getting mails through spam filters at gmail and others - eg if some domains on a server are sending bulk mails, newsletters,... it's better other mail is going out over a different IP.

runout-at commented 6 years ago

I asked the debian packagers to integrate the code for the transports in their package: http://lists.alioth.debian.org/pipermail/pkg-exim4-users/2018-April/thread.html#2385

runout-at commented 6 months ago

A rework of this PR makes sense since Debian has integrated this in the default configs now.

I did use the variable _OUTGOING_IPADDRESSES. Debian uses _REMOTE_SMTPINTERFACE. That's the only difference.

We only really need the changes in the DB and a config setting to read the IP from the database like:

VEXIM_OUTIP = SELECT DISTINCT out_ip FROM domains \
                           WHERE domain = '${quote_mysql:$sender_address_domain}' \
                               AND out_ip <> TRIM('')
OUTGOING_IP_DEFAULT = 2001:db8:: ; 10.0.0.1
REMOTE_SMTP_INTERFACE = ${lookup mysql{VEXIM_OUTIP}{ <; $value }{ <; OUTGOING_IP_DEFAULT }}
Udera commented 6 months ago

How does the smtp transport know which ip to use (or is this already hidden somewhere)? You just add all of the ip addresses:

The first interface of the correct type (IPv4 or IPv6) is used for the outgoing connection.

https://www.exim.org/exim-html-current/doc/html/spec_html/ch-the_smtp_transport.html

runout-at commented 6 months ago

In Debian split config its in transport/30_exim4-config_remote_smtp

.ifdef REMOTE_SMTP_INTERFACE
  interface = REMOTE_SMTP_INTERFACE
.endif

My code from above https://github.com/vexim/vexim2/pull/245#issuecomment-1889225874 does set the variable _REMOTE_SMTPINTERFACE from the DB-query or a default value.

runout-at commented 6 months ago

After reading your comment again, I'm not sure I did understand your question right. Maybe my answer was not sufficient.

If multiple IPs are given in _REMOTE_SMTPINTERFACE, Exim will try each until it finds one that is sufficient. Eg if the connection is IPv4 and the first addresses given are IPv6 it will skip it. At least it works like that on my production sever for several years now.