Skip to content

Commit 13d6654

Browse files
committed
outbound: add inet_prefer to configure outbound IPv4/IPv6 preference
1 parent 574a8e1 commit 13d6654

File tree

5 files changed

+37
-0
lines changed

5 files changed

+37
-0
lines changed

Changes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
1111
- feat(rabbitmq_amqplib): configurable message priority #3472
1212
- add save-sent to Plugins.md
1313
- deferred hook is now passed the failed recips list and mx info
14+
- feat(outbound): configurable outbound IPv4/IPv6 preference using `inet_prefer`
1415

1516
### [3.1.1] - 2025-05-19
1617

config/outbound.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@
1919

2020
; received_header (default: "Haraka outbound")
2121
; received_header=Haraka outbound
22+
23+
; inet_prefer (default: default)
24+
; inet_prefer=v4

docs/Outbound.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ Default: false. By default, outbound to a local IP is disabled, to avoid creatin
5353

5454
Set this to specify the delay intervals to use between trying to re-send an email that has a temporary failure condition. The setting is a comma separated list of time spans and multipliers. The time span is a number followed by `s`, `m`, `h`, or `d` to represent seconds, minutes, hours, and days, respectively. The multiplier is an asterisk followed by an integer representing the number of times to repeat the interval. For example, the entry `1m, 5m*2, 1h*3` results in an array of delay times of `[60,300,300,3600,3600,3600]` in seconds. The email will be bounced when the array runs out of intervals (the 7th failure in this case). Set this to `none` to bounce the email on the first temporary failure.
5555

56+
* `inet_prefer`
57+
58+
Default: default. Selects the preferred address family (IP version) to deliver messages.
59+
60+
| Value | Description |
61+
|------------------------|-------------|
62+
| `default` | Prefer IPv6 when IPv4 and IPv6 IPs exist at the same MX priority |
63+
| `v4` | Try IPv4 addresses first, then IPv6 |
64+
| `v6` | Try IPv6 addresses first, then IPv4 |
65+
66+
Note: Delivery attempts follow MX priority order. Socket-based deliveries ignore this setting.
67+
5668
### outbound.bounce\_message
5769

5870
See "Bounce Messages" below for details.

outbound/config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ function load_config () {
1717
load_config();
1818
}).main;
1919

20+
if (!cfg.inet_prefer) cfg.inet_prefer = 'default';
21+
if (!cfg.inet_prefer.match(/^(v4|v6|default)$/)) {
22+
logger.warn(exports, `inet_prefer is set to an invalid value: ${cfg.inet_prefer}`);
23+
cfg.inet_prefer = 'default';
24+
}
25+
2026
// legacy config file support. Remove in Haraka 4.0
2127
if (!cfg.disabled && config.get('outbound.disabled')) {
2228
cfg.disabled = true;

outbound/hmail.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,21 @@ class HMailItem extends events.EventEmitter {
269269
// resolves the MX hostnames to IPs
270270
this.mxlist = await net_utils.resolve_mx_hosts(mxs);
271271

272+
switch (obc.cfg.inet_prefer) {
273+
case 'v4':
274+
this.mxlist = [
275+
...this.mxlist.filter(mx => !net.isIP(mx.exchange) || net.isIPv4(mx.exchange)),
276+
...this.mxlist.filter(mx => net.isIPv6(mx.exchange))
277+
];
278+
break;
279+
case 'v6':
280+
this.mxlist = [
281+
...this.mxlist.filter(mx => !net.isIP(mx.exchange) || net.isIPv6(mx.exchange)),
282+
...this.mxlist.filter(mx => net.isIPv4(mx.exchange))
283+
];
284+
break;
285+
}
286+
272287
this.try_deliver();
273288
}
274289

0 commit comments

Comments
 (0)