Haraka 3.1.4 → 3.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierignore +1 -1
- package/{Changes.md → CHANGELOG.md} +34 -0
- package/CONTRIBUTORS.md +26 -26
- package/README.md +68 -93
- package/SECURITY.md +178 -0
- package/bin/haraka +7 -14
- package/config/plugins +0 -3
- package/docs/Connection.md +126 -39
- package/docs/CoreConfig.md +92 -74
- package/docs/HAProxy.md +41 -25
- package/docs/Logging.md +68 -38
- package/docs/Outbound.md +124 -179
- package/docs/Plugins.md +38 -59
- package/docs/Transaction.md +78 -83
- package/docs/Tutorial.md +122 -209
- package/docs/plugins/aliases.md +1 -141
- package/docs/plugins/auth/auth_ldap.md +2 -39
- package/docs/plugins/max_unrecognized_commands.md +4 -18
- package/docs/plugins/process_title.md +3 -3
- package/docs/plugins/reseed_rng.md +11 -13
- package/docs/plugins/tls.md +7 -7
- package/docs/plugins/toobusy.md +10 -4
- package/docs/tutorials/SettingUpOutbound.md +40 -48
- package/endpoint.js +32 -2
- package/outbound/hmail.js +3 -2
- package/outbound/index.js +3 -0
- package/package.json +21 -34
- package/plugins/queue/smtp_forward.js +4 -4
- package/run_tests +3 -15
- package/server.js +17 -7
- package/smtp_client.js +8 -6
- package/test/connection.js +234 -0
- package/test/endpoint.js +32 -4
- package/test/host_pool.js +57 -31
- package/test/logger.js +75 -135
- package/test/outbound/bounce_net_errors.js +87 -131
- package/test/outbound/bounce_rfc3464.js +177 -254
- package/test/outbound/hmail.js +19 -0
- package/test/outbound/index.js +189 -0
- package/test/outbound/queue.js +92 -0
- package/test/plugins/auth/auth_base.js +39 -44
- package/test/plugins/auth/auth_vpopmaild.js +8 -9
- package/test/plugins/queue/smtp_forward.js +953 -183
- package/test/plugins/rcpt_to.host_list_base.js +58 -93
- package/test/plugins/rcpt_to.in_host_list.js +126 -175
- package/test/plugins/record_envelope_addresses.js +8 -8
- package/test/plugins/status.js +10 -10
- package/test/plugins/tls.js +9 -19
- package/test/plugins/xclient.js +75 -110
- package/test/plugins.js +10 -13
- package/test/rfc1869.js +50 -70
- package/test/server.js +438 -421
- package/test/smtp_client.js +1192 -218
- package/test/tls_socket.js +242 -0
- package/tls_socket.js +18 -22
package/docs/Outbound.md
CHANGED
|
@@ -1,265 +1,210 @@
|
|
|
1
1
|
# Outbound Mail with Haraka
|
|
2
2
|
|
|
3
|
-
A default
|
|
3
|
+
A default Haraka installation queues outbound mail to disk and delivers it to the appropriate MX for each recipient domain. Temporary failures are retried automatically using the configured backoff schedule.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
A mail is treated as outbound when a plugin sets `connection.relaying` to `true`. The simplest way is SMTP AUTH using `auth/flat_file` or one of the [auth plugins](plugins/auth/); the `relay` plugin offers allow-list-based variants, and a custom plugin can apply any policy.
|
|
6
6
|
|
|
7
|
-
For
|
|
7
|
+
For live stats on the outbound queue see the [`process_title`](plugins/process_title.md) plugin.
|
|
8
8
|
|
|
9
|
-
To flush the
|
|
9
|
+
To flush the temp-fail queue (e.g. after fixing network or DNS), send `SIGHUP` to the Haraka master process.
|
|
10
10
|
|
|
11
|
-
## Outbound Configuration
|
|
11
|
+
## Outbound Configuration
|
|
12
12
|
|
|
13
13
|
### outbound.ini
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
Within `tls.ini` you can specify global options for the values `ciphers`, `minVersion`, `requestCert` and `rejectUnauthorized`, alternatively you can provide separate values by putting them under a key: `[outbound]`, such as:
|
|
15
|
+
| Key | Default | Description |
|
|
16
|
+
| --- | --- | --- |
|
|
17
|
+
| `disabled` | `false` | Pause outbound delivery while still queuing inbound mail. Reloadable at runtime. |
|
|
18
|
+
| `concurrency_max` | `10000` | Maximum concurrent outbound deliveries **per worker**. Effective total is `concurrency_max × nodes`. |
|
|
19
|
+
| `enable_tls` | `true` | Use opportunistic STARTTLS on outbound. |
|
|
20
|
+
| `maxTempFailures` | `13` | Maximum temp-fail retries before the message bounces. Ignored if `temp_fail_intervals` is set. |
|
|
21
|
+
| `temp_fail_intervals` | derived | Comma-separated `<n><unit>[*<count>]` pattern. `1m, 5m*2, 1h*3` → `[60,300,300,3600,3600,3600]` seconds. `none` bounces on first temp-fail. |
|
|
22
|
+
| `always_split` | `false` | Create one queue file per recipient (instead of one per destination domain). Hurts throughput but simplifies bounce handling. |
|
|
23
|
+
| `received_header` | `Haraka outbound` | Text used in the outbound `Received:` header. Set to the literal `disabled` to omit it. |
|
|
24
|
+
| `connect_timeout` | `30` | Seconds to wait for TCP connect to the remote MX. |
|
|
25
|
+
| `local_mx_ok` | `false` | Allow outbound delivery to local/private IPs (otherwise blocked to prevent loops). |
|
|
26
|
+
| `inet_prefer` | `default` | `default` (prefer IPv6 at equal MX priority), `v4`, or `v6`. Delivery still follows MX priority. |
|
|
27
|
+
|
|
28
|
+
TLS configuration is shared with the `tls` plugin (`tls_key.pem`, `tls_cert.pem`, and `tls.ini`). Outbound-specific overrides go under `[outbound]` in `tls.ini`:
|
|
30
29
|
|
|
31
30
|
```ini
|
|
32
31
|
[outbound]
|
|
33
32
|
ciphers=!DES
|
|
33
|
+
minVersion=TLSv1.2
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
- `always_split`
|
|
37
|
-
|
|
38
|
-
Default: false. By default, Haraka groups message recipients by domain so that messages with multiple recipients at the same domain get sent in a single SMTP session. When `always_split` is enabled, each recipient gets a queue entry and delivery in its own SMTP session. This carries a performance penalty but enables more flexibility in mail delivery and bounce handling.
|
|
39
|
-
|
|
40
|
-
- `received_header`
|
|
41
|
-
|
|
42
|
-
Default: "Haraka outbound". If this text is any string except _disabled_, the string is attached as a `Received` header to all outbound mail just before it is queued.
|
|
43
|
-
|
|
44
|
-
- `connect_timeout`
|
|
45
|
-
|
|
46
|
-
Timeout for connecting to remote servers. Default: 30s
|
|
47
|
-
|
|
48
|
-
- `local_mx_ok`
|
|
49
|
-
|
|
50
|
-
Default: false. By default, outbound to a local IP is disabled, to avoid creating mail loops. Set this to true if you want to allow outbound to local IPs. This could be useful if you want to deliver mail to private IPs or localhost on another port.
|
|
51
|
-
|
|
52
|
-
- `temp_fail_intervals`
|
|
53
|
-
|
|
54
|
-
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.
|
|
55
|
-
|
|
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
|
-
|
|
68
36
|
### outbound.bounce_message
|
|
69
37
|
|
|
70
|
-
See "Bounce Messages" below
|
|
38
|
+
Template for the bounce message body. See "Bounce Messages" below.
|
|
71
39
|
|
|
72
40
|
## The HMail Object
|
|
73
41
|
|
|
74
|
-
|
|
42
|
+
Most outbound hooks pass an `hmail` (HMailItem). You rarely need its methods, but these properties are useful:
|
|
75
43
|
|
|
76
|
-
|
|
44
|
+
| Property | Description |
|
|
45
|
+
| --- | --- |
|
|
46
|
+
| `path` | Full filesystem path to the queue file. |
|
|
47
|
+
| `filename` | Queue file's base name. |
|
|
48
|
+
| `num_failures` | Number of temp-fail attempts so far. |
|
|
49
|
+
| `notes` | Plain object for plugin state, scoped to this queue item. |
|
|
50
|
+
| `todo` | The `TODOItem` describing what to deliver (see below). |
|
|
77
51
|
|
|
78
|
-
The
|
|
52
|
+
## The TODO Object
|
|
79
53
|
|
|
80
|
-
|
|
81
|
-
- filename - the filename within the queue dir
|
|
82
|
-
- num_failures - the number of times this mail has been temp failed
|
|
83
|
-
- notes - notes you can store on a hmail object (similar to `transaction.notes`) to allow you to pass information between outbound hooks
|
|
84
|
-
- todo - see below
|
|
54
|
+
`hmail.todo` describes the delivery:
|
|
85
55
|
|
|
86
|
-
|
|
56
|
+
| Property | Description |
|
|
57
|
+
| --- | --- |
|
|
58
|
+
| `mail_from` | `Address`<sup>[1](#fn1)</sup> — the envelope sender. |
|
|
59
|
+
| `rcpt_to` | `Address`<sup>[1](#fn1)</sup> array — envelope recipients. |
|
|
60
|
+
| `domain` | Recipient domain (a single domain unless `always_split` is set). |
|
|
61
|
+
| `notes` | The original `transaction.notes`. Keys you may set: |
|
|
62
|
+
| `notes.outbound_ip` | IP to bind the outbound socket to. **Set via the `get_mx` hook**, not directly. |
|
|
63
|
+
| `notes.outbound_helo` | EHLO domain. **Set via the `get_mx` hook**, not directly. |
|
|
64
|
+
| `queue_time` | When the mail was queued (epoch ms). |
|
|
65
|
+
| `uuid` | Inherited from the source `transaction.uuid`. |
|
|
66
|
+
| `force_tls` | If `true`, defer instead of delivering in plaintext. |
|
|
87
67
|
|
|
88
|
-
|
|
68
|
+
## Outbound Hooks
|
|
89
69
|
|
|
90
|
-
|
|
91
|
-
- mail_from - an Address<sup>[1](#fn1)</sup> object - the rfc.2821 sender of this mail
|
|
92
|
-
- domain - the domain this mail is going to (see `always_split` above)
|
|
93
|
-
- notes - the original transaction.notes for this mail, also contains the following useful keys:
|
|
94
|
-
- outbound_ip - the IP address to bind to (do not set manually, use the `get_mx` hook)
|
|
95
|
-
- outbound_helo - the EHLO domain to use (again, do not set manually)
|
|
96
|
-
- queue_time - the epoch milliseconds time when this mail was queued
|
|
97
|
-
- uuid - the original transaction.uuid
|
|
98
|
-
- force_tls - if true, this mail will be sent over TLS or defer
|
|
70
|
+
### queue_outbound
|
|
99
71
|
|
|
100
|
-
|
|
72
|
+
Runs before queuing. Returning `CONT` (or having no hook) queues the mail. `OK` indicates the plugin queued it itself; the `DENY*` codes reject the message.
|
|
101
73
|
|
|
102
|
-
###
|
|
74
|
+
### pre_send_trans_email
|
|
103
75
|
|
|
104
|
-
|
|
76
|
+
Parameters: `next, connection`
|
|
105
77
|
|
|
106
|
-
|
|
78
|
+
Fired by `outbound.send_trans_email()` before the transaction is serialized to disk. Useful for plugins that synthesize mail programmatically — they can attach final headers or notes here.
|
|
107
79
|
|
|
108
|
-
|
|
80
|
+
### send_email
|
|
109
81
|
|
|
110
|
-
|
|
82
|
+
Parameters: `next, hmail`
|
|
111
83
|
|
|
112
|
-
|
|
84
|
+
Called just before delivery starts. `next(DELAY, seconds)` defers the attempt.
|
|
113
85
|
|
|
114
|
-
###
|
|
86
|
+
### get_mx
|
|
115
87
|
|
|
116
88
|
Parameters: `next, hmail, domain`
|
|
117
89
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
The MX is sent via next(OK, mx). `mx` is a [HarakaMx][url-harakamx] object, an array of HarakaMx objects, or any suitable HarakaMx input.
|
|
121
|
-
|
|
122
|
-
### The deferred hook
|
|
90
|
+
Called when delivery begins, with the destination domain. Plugins can override MX lookup; most installs leave Haraka to do DNS. Respond with `next(OK, mx)` where `mx` is a [HarakaMx][url-harakamx] object, an array of them, or any HarakaMx-compatible input. Set `mx.auth_user` / `mx.auth_pass` to AUTH against the remote, or `mx.bind` / `mx.bind_helo`
|
|
91
|
+
to control source address and EHLO.
|
|
123
92
|
|
|
124
|
-
|
|
93
|
+
### deferred
|
|
125
94
|
|
|
126
|
-
|
|
95
|
+
Parameters: `next, hmail, { delay, err }`
|
|
127
96
|
|
|
128
|
-
|
|
97
|
+
Fired on temporary failure. Return `OK` to drop the mail silently; return `DENYSOFT, seconds` to override the retry delay (useful for custom backoff indexed on `hmail.num_failures`).
|
|
129
98
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
### The bounce hook
|
|
99
|
+
### bounce
|
|
133
100
|
|
|
134
101
|
Parameters: `next, hmail, error`
|
|
135
102
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
- mx - the MX object that caused the bounce
|
|
139
|
-
- deferred_rcpt - the deferred recipients that eventually bounced
|
|
140
|
-
- bounced_rcpt - the bounced recipients
|
|
141
|
-
|
|
142
|
-
If you do not wish to have a bounce message sent to the originating sender of the email then you can return `OK` from this hook to stop it from sending a bounce message.
|
|
143
|
-
|
|
144
|
-
### The delivered hook
|
|
145
|
-
|
|
146
|
-
Parameters: `next, hmail, params`
|
|
103
|
+
Fired on permanent failure (5xx). Not called for temp-fails. `error` may carry:
|
|
147
104
|
|
|
148
|
-
|
|
105
|
+
- `mx` — the MX that caused the bounce
|
|
106
|
+
- `deferred_rcpt` — recipients that eventually bounced after deferrals
|
|
107
|
+
- `bounced_rcpt` — recipients that bounced outright
|
|
149
108
|
|
|
150
|
-
|
|
109
|
+
Return `OK` to suppress the DSN to the original sender.
|
|
151
110
|
|
|
152
|
-
|
|
153
|
-
- `ip` - IP address of the host that the message was delivered to,
|
|
154
|
-
- `response` - Variable contains the SMTP response text returned by the host that received the message and will typically contain the remote queue ID and
|
|
155
|
-
- `delay` - Time taken between the queue file being created and the message being delivered.
|
|
156
|
-
- `port` - Port number that the message was delivered to.
|
|
157
|
-
- `mode` - Shows whether SMTP or LMTP was used to deliver the mail.
|
|
158
|
-
- `ok_recips` - an `Address`<sup>[1](#fn1)</sup> array containing all of the recipients that were successfully delivered to.
|
|
159
|
-
- `secured` - A boolean denoting if the connection used TLS or not.
|
|
111
|
+
### delivered
|
|
160
112
|
|
|
161
|
-
|
|
113
|
+
Parameters: `next, hmail, [host, ip, response, delay, port, mode, ok_recips, secured, authenticated]`
|
|
162
114
|
|
|
163
|
-
|
|
115
|
+
Fired after a successful delivery. Return codes are ignored; the hook is for logging / accounting.
|
|
164
116
|
|
|
165
|
-
|
|
117
|
+
| Element | Description |
|
|
118
|
+
| --- | --- |
|
|
119
|
+
| `host` | Hostname of the receiving MX. |
|
|
120
|
+
| `ip` | IP we delivered to. |
|
|
121
|
+
| `response` | Remote SMTP response text (typically includes the remote queue ID). |
|
|
122
|
+
| `delay` | Seconds between queue write and delivery. |
|
|
123
|
+
| `port` | Destination port. |
|
|
124
|
+
| `mode` | `'smtp'` or `'lmtp'`. |
|
|
125
|
+
| `ok_recips` | `Address`<sup>[1](#fn1)</sup> array of successfully delivered recipients. |
|
|
126
|
+
| `secured` | `true` if STARTTLS succeeded. |
|
|
127
|
+
| `authenticated` | `true` if outbound AUTH succeeded. |
|
|
166
128
|
|
|
167
|
-
|
|
129
|
+
## Outbound IP Address
|
|
168
130
|
|
|
169
|
-
|
|
131
|
+
By default the OS routing table chooses the source IP. To pin outbound to a specific IP (per-sender, per-domain, etc.), bind that address to a local interface or alias, then set `mx.bind` (source IP) and `mx.bind_helo` (EHLO domain) in your `get_mx` hook.
|
|
170
132
|
|
|
171
|
-
|
|
133
|
+
## Outbound AUTH
|
|
172
134
|
|
|
173
|
-
|
|
135
|
+
Force AUTH for a domain or smart host by returning an MX with `auth_user` and `auth_pass` set from the `get_mx` hook. If the remote end does not advertise AUTH (or no compatible mechanism is found), delivery proceeds without AUTH and a warning is logged.
|
|
174
136
|
|
|
175
137
|
## Bounce Messages
|
|
176
138
|
|
|
177
|
-
The
|
|
139
|
+
The bounce body comes from `config/outbound.bounce_message`. Curly-brace template variables are filled in at bounce time:
|
|
178
140
|
|
|
179
|
-
|
|
141
|
+
- `pid` — current process id
|
|
142
|
+
- `date` — bounce timestamp
|
|
143
|
+
- `me` — contents of `config/me`
|
|
144
|
+
- `from` — original sender
|
|
145
|
+
- `msgid` — original message UUID
|
|
146
|
+
- `to` — original recipient (or first, for multi-recipient mail)
|
|
147
|
+
- `reason` — remote server's rejection text
|
|
180
148
|
|
|
181
|
-
|
|
182
|
-
- date - the current date when the bounce occurred
|
|
183
|
-
- me - the contents of `config/me`
|
|
184
|
-
- from - the originating sender of the message
|
|
185
|
-
- msgid - a uuid for the mail
|
|
186
|
-
- to - the end recipient of the message, or the first recipient if it was to
|
|
187
|
-
multiple people
|
|
188
|
-
- reason - the text from the remote server indicating why it bounced
|
|
149
|
+
The original message is appended to the bounce.
|
|
189
150
|
|
|
190
|
-
|
|
151
|
+
For HTML bounces, add `config/outbound.bounce_message_html` (and optionally an inline image in `config/outbound.bounce_message_image`).
|
|
191
152
|
|
|
192
|
-
##
|
|
153
|
+
## Generating Mail from a Plugin
|
|
193
154
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
To do that, you can use the `outbound` module directly:
|
|
155
|
+
To create and queue a new message from inside a plugin, use the `outbound` module:
|
|
197
156
|
|
|
198
157
|
```js
|
|
199
158
|
const outbound = require('./outbound')
|
|
200
159
|
|
|
201
|
-
const to = 'user@example.com'
|
|
202
160
|
const from = 'sender@example.com'
|
|
161
|
+
const to = 'user@example.com'
|
|
203
162
|
|
|
204
163
|
const contents = [
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
164
|
+
`From: ${from}`,
|
|
165
|
+
`To: ${to}`,
|
|
166
|
+
'MIME-Version: 1.0',
|
|
167
|
+
'Content-Type: text/plain; charset=us-ascii',
|
|
168
|
+
'Subject: Hello',
|
|
169
|
+
'',
|
|
170
|
+
'Body here.',
|
|
171
|
+
'',
|
|
213
172
|
].join('\n')
|
|
214
173
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
this.logerror('Unrecognized return code from sending email: ' + msg)
|
|
226
|
-
next()
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
outbound.send_email(from, to, contents, outnext)
|
|
174
|
+
outbound.send_email(from, to, contents, (code, msg) => {
|
|
175
|
+
switch (code) {
|
|
176
|
+
case OK:
|
|
177
|
+
plugin.loginfo('queued')
|
|
178
|
+
break
|
|
179
|
+
case DENY:
|
|
180
|
+
plugin.logerror(`queue failed: ${msg}`)
|
|
181
|
+
break
|
|
182
|
+
}
|
|
183
|
+
})
|
|
231
184
|
```
|
|
232
185
|
|
|
233
|
-
The callback
|
|
186
|
+
The callback fires when the mail is **queued**, not delivered — hook `delivered` and `bounce` to observe delivery outcomes.
|
|
234
187
|
|
|
235
|
-
The callback
|
|
188
|
+
The callback may be omitted if you don't need to handle queue failure:
|
|
236
189
|
|
|
237
190
|
```js
|
|
238
191
|
outbound.send_email(from, to, contents)
|
|
239
192
|
```
|
|
240
193
|
|
|
241
|
-
|
|
194
|
+
Options accepted by `send_email(from, to, contents, next, options)`:
|
|
242
195
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
196
|
+
| Option | Description |
|
|
197
|
+
| --- | --- |
|
|
198
|
+
| `dot_stuffed: true` | Content is already SMTP dot-stuffed. |
|
|
199
|
+
| `notes: { … }` | Seed the new transaction's `notes`. |
|
|
200
|
+
| `remove_msgid: true` | Drop any existing `Message-Id:` so Haraka generates one. Useful when releasing from quarantine. |
|
|
201
|
+
| `remove_date: true` | Drop any existing `Date:` so Haraka generates one. |
|
|
202
|
+
| `origin: <object>` | Object passed to the logger to identify the source plugin / connection / HMailItem. |
|
|
246
203
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
| Key/Value | Description |
|
|
250
|
-
| ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
251
|
-
| `dot_stuffed: true` | Use this if you are passing your content dot-stuffed (a dot at the start of a line is doubled, like it is in SMTP conversation, see [RFC 2821][url-rfc2821]. |
|
|
252
|
-
| `notes: { key: value}` | In case you need notes in the new transaction that `send_email()` creates. |
|
|
253
|
-
| `remove_msgid: true` | Remove any Message-Id header found in the message. If you are reading a message in from the filesystem and you want to ensure that a generated Message-Id header is used in preference over the original. This is useful if you are releasing mail from a quarantine. |
|
|
254
|
-
| `remove_date: true` | Remove any Date header found in the message. If you are reading a message in from the filesystem and you want to ensure that a generated Date header is used in preference over the original. This is useful if you are releasing mail from a quarantine. |
|
|
255
|
-
| `origin: Object` | Adds object as argument to logger.log calls inside outbound.send_email. Useful for tracking which Plugin/Connection/HMailItem object generated email. |
|
|
256
|
-
|
|
257
|
-
```js
|
|
258
|
-
outbound.send_email(from, to, contents, outnext, { notes: transaction.notes })
|
|
259
|
-
```
|
|
204
|
+
To send an already-built `Transaction` directly, use `outbound.send_trans_email(transaction, next)`. This is what `send_email()` calls internally and fires the `pre_send_trans_email` hook.
|
|
260
205
|
|
|
261
206
|
<a name="fn1">1</a>: `Address` objects are [address-rfc2821](https://github.com/haraka/node-address-rfc2821) objects.
|
|
262
207
|
|
|
263
|
-
[url-tls]:
|
|
208
|
+
[url-tls]: plugins/tls.md
|
|
264
209
|
[url-harakamx]: https://github.com/haraka/haraka-net-utils?tab=readme-ov-file#harakamx
|
|
265
210
|
[url-rfc2821]: https://tools.ietf.org/html/rfc2821#section-4.5.2
|
package/docs/Plugins.md
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# Plugins
|
|
2
2
|
|
|
3
|
-
Most aspects of receiving an email in Haraka are controlled by plugins. Mail cannot even be received unless at least a 'rcpt' and 'queue' plugin are
|
|
4
|
-
enabled.
|
|
3
|
+
Most aspects of receiving an email in Haraka are controlled by plugins. Mail cannot even be received unless at least a 'rcpt' and 'queue' plugin are enabled.
|
|
5
4
|
|
|
6
5
|
Recipient (_rcpt_) plugins determine if a particular recipient is allowed to be relayed or received for. A _queue_ plugin queues the message somewhere - normally to disk or to an another SMTP server.
|
|
7
6
|
|
|
@@ -9,7 +8,7 @@ Recipient (_rcpt_) plugins determine if a particular recipient is allowed to be
|
|
|
9
8
|
|
|
10
9
|
Get a list of installed plugins by running `haraka -l`. To include locally installed plugins, add the `-c /path/to/config` option.
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
The [top-level Plugins.md](../Plugins.md) is the registry of known plugins — both core and community.
|
|
13
12
|
|
|
14
13
|
Display the help text for a plugin by running:
|
|
15
14
|
|
|
@@ -21,12 +20,9 @@ Display the help text for a plugin by running:
|
|
|
21
20
|
|
|
22
21
|
## Anatomy of a Plugin
|
|
23
22
|
|
|
24
|
-
Plugins in Haraka are JS files in the `plugins` directory (legacy) and npm
|
|
25
|
-
modules in the node_modules directory. See "Plugins as Modules" below.
|
|
23
|
+
Plugins in Haraka are JS files in the `plugins` directory (legacy) and npm modules in the node_modules directory. See "Plugins as Modules" below.
|
|
26
24
|
|
|
27
|
-
Plugins can be installed in the Haraka global directory (default:
|
|
28
|
-
/$os/$specific/lib/node_modules/Haraka) or in the Haraka install directory
|
|
29
|
-
(whatever you chose when you typed `haraka -i`. Example: `haraka -i /etc/haraka`
|
|
25
|
+
Plugins can be installed in the Haraka global directory (default: /$os/$specific/lib/node_modules/Haraka) or in the Haraka install directory (whatever you chose when you typed `haraka -i`. Example: `haraka -i /etc/haraka`
|
|
30
26
|
|
|
31
27
|
To enable a plugin, add its name to `config/plugins`. For npm packaged plugins, the name does not include the `haraka-plugin` prefix.
|
|
32
28
|
|
|
@@ -123,6 +119,8 @@ need to define them:
|
|
|
123
119
|
|
|
124
120
|
- DENYDISCONNECT - Reject with a 5xx error and immediately disconnect.
|
|
125
121
|
|
|
122
|
+
- DENYSOFTDISCONNECT - Reject with a 4xx error and immediately disconnect.
|
|
123
|
+
|
|
126
124
|
- DISCONNECT - Immediately disconnect
|
|
127
125
|
|
|
128
126
|
- OK
|
|
@@ -178,6 +176,7 @@ These are the hook and their parameters (next excluded):
|
|
|
178
176
|
- delivered (hmail, [host, ip, response, delay, port, mode, ok_recips, secured, authenticated]) - called when outbound mail is delivered
|
|
179
177
|
- send_email (hmail) - called when outbound is about to be sent
|
|
180
178
|
- pre_send_trans_email (fake_connection) - called just before an email is queued to disk with a faked connection object
|
|
179
|
+
- log (logger, log_item) - called for every log message; log plugins (e.g. haraka-plugin-syslog) use this hook to ship logs elsewhere
|
|
181
180
|
|
|
182
181
|
### rcpt
|
|
183
182
|
|
|
@@ -287,47 +286,28 @@ Plugins inherit all the logging methods of `logger.js`, which are:
|
|
|
287
286
|
- logalert
|
|
288
287
|
- logemerg
|
|
289
288
|
|
|
290
|
-
If plugins throw an exception when in a hook, the exception will be caught
|
|
291
|
-
and generate a logcrit level error. However, exceptions will not be caught
|
|
292
|
-
as gracefully when plugins are running async code. Use error codes for that,
|
|
293
|
-
log the error, and run your next() function appropriately.
|
|
289
|
+
If plugins throw an exception when in a hook, the exception will be caught and generate a logcrit level error. However, exceptions will not be caught as gracefully when plugins are running async code. Use error codes for that, log the error, and run your next() function appropriately.
|
|
294
290
|
|
|
295
291
|
## Sharing State
|
|
296
292
|
|
|
297
|
-
There are several cases where you might need to share information between
|
|
298
|
-
plugins. This is done using `notes` - there are three types available:
|
|
293
|
+
There are several cases where you might need to share information between plugins. This is done using `notes` - there are three types available:
|
|
299
294
|
|
|
300
295
|
- server.notes
|
|
301
296
|
|
|
302
|
-
Available in all plugins. This is created at PID start-up and is shared
|
|
303
|
-
amongst all plugins on the same PID and listener.
|
|
304
|
-
Typical uses for notes at this level would be to share database
|
|
305
|
-
connections between multiple plugins or connection pools etc.
|
|
297
|
+
Available in all plugins. This is created at PID start-up and is shared amongst all plugins on the same PID and listener. Typical uses for notes at this level would be to share database connections between multiple plugins or connection pools etc.
|
|
306
298
|
|
|
307
299
|
- connection.notes
|
|
308
300
|
|
|
309
|
-
Available on any hook that passes 'connection' as a function parameter.
|
|
310
|
-
This is shared amongst all plugins for a single connection and is
|
|
311
|
-
destroyed after the client disconnects.
|
|
312
|
-
Typical uses for notes at this level would be to store information
|
|
313
|
-
about the connected client e.g. rDNS names, HELO/EHLO, white/black
|
|
314
|
-
list status etc.
|
|
301
|
+
Available on any hook that passes 'connection' as a function parameter. This is shared amongst all plugins for a single connection and is destroyed after the client disconnects. Typical uses for notes at this level would be to store information about the connected client e.g. rDNS names, HELO/EHLO, white/black list status etc.
|
|
315
302
|
|
|
316
303
|
- connection.transaction.notes
|
|
317
304
|
|
|
318
|
-
Available on any hook that passes 'connection' as a function parameter
|
|
319
|
-
|
|
320
|
-
This is shared amongst all plugins for this transaction (e.g. MAIL FROM
|
|
321
|
-
through until a message is received or the connection is reset).
|
|
322
|
-
Typical uses for notes at this level would be to store information
|
|
323
|
-
on things like greylisting which uses client, sender and recipient
|
|
324
|
-
information etc.
|
|
305
|
+
Available on any hook that passes 'connection' as a function parameter between hook_mail and hook_data_post.
|
|
306
|
+
This is shared amongst all plugins for this transaction (e.g. MAIL FROM through until a message is received or the connection is reset). Typical uses for notes at this level would be to store information on things like greylisting which uses client, sender and recipient information etc.
|
|
325
307
|
|
|
326
308
|
- hmail.todo.notes
|
|
327
309
|
|
|
328
|
-
Available on any outbound hook that passes `hmail` as a function parameter.
|
|
329
|
-
This is the same object as 'connection.transaction.notes', so anything
|
|
330
|
-
you store in the transaction notes is automatically available in the
|
|
310
|
+
Available on any outbound hook that passes `hmail` as a function parameter. This is the same object as 'connection.transaction.notes', so anything you store in the transaction notes is automatically available in the
|
|
331
311
|
outbound functions here.
|
|
332
312
|
|
|
333
313
|
All of these notes are JS objects - use them as simple key/value store e.g.
|
|
@@ -336,39 +316,40 @@ All of these notes are JS objects - use them as simple key/value store e.g.
|
|
|
336
316
|
|
|
337
317
|
## Plugins as Modules
|
|
338
318
|
|
|
339
|
-
Plugins as NPM modules are named with the `haraka-plugin` prefix. Therefore, a
|
|
340
|
-
plugin that frobnobricates might be called `haraka-plugin-frobnobricate` and
|
|
341
|
-
published to NPM with that name. The prefix is not required in the
|
|
319
|
+
Plugins as NPM modules are named with the `haraka-plugin` prefix. Therefore, a plugin that frobnobricates might be called `haraka-plugin-frobnobricate` and published to NPM with that name. The prefix is not required in the
|
|
342
320
|
`config/plugins` file.
|
|
343
321
|
|
|
344
|
-
Plugins loaded as NPM modules behave slightly different than plugins loaded
|
|
345
|
-
|
|
322
|
+
Plugins loaded as NPM modules behave slightly different than plugins loaded as plain JS files.
|
|
323
|
+
|
|
324
|
+
Plain JS plugins have a custom `require()` which allows loading core Haraka modules via specifying `require('./name')` (note the `./` prefix). Although the core modules aren't in the same folder, the custom `require` intercepts
|
|
325
|
+
this and look for core modules. Note that if there is a module in your plugins folder of the same name that will not take preference, so avoid using names similar to core modules.
|
|
326
|
+
|
|
327
|
+
Plugins loaded as modules do not have the special `require()`. To load a core Haraka module you must use `this.haraka_require('name')`. This should also be preferred for plain JS plugins, as the `./` hack is likely to be removed in the future.
|
|
328
|
+
|
|
329
|
+
Plugins loaded as modules are not compiled in the Haraka plugin sandbox, which blocks access to certain globals and provides a global `server` object. To access the `server` object, use `connection.server` instead.
|
|
330
|
+
|
|
331
|
+
Module plugins support default config in their local `config` directory. See the "Default Config and Overrides" section in [haraka-config](https://github.com/haraka/haraka-config#default-config-and-overrides).
|
|
346
332
|
|
|
347
|
-
|
|
348
|
-
modules via specifying `require('./name')` (note the `./` prefix). Although
|
|
349
|
-
the core modules aren't in the same folder, the custom `require` intercepts
|
|
350
|
-
this and look for core modules. Note that if there is a module in your plugins
|
|
351
|
-
folder of the same name that will not take preference, so avoid using names
|
|
352
|
-
similar to core modules.
|
|
333
|
+
### Inheriting from another plugin
|
|
353
334
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
335
|
+
A plugin can inherit methods from another plugin by calling `plugin.inherits(name)` from its `register()`. The parent's exported methods become available on `this` (without overwriting any methods the child has already defined), and the parent's `register()` runs in the child's context. `rcpt_to.host_list_base` is a typical parent used by multiple `rcpt_to.*` plugins.
|
|
336
|
+
|
|
337
|
+
```js
|
|
338
|
+
exports.register = function () {
|
|
339
|
+
this.inherits('rcpt_to.host_list_base')
|
|
340
|
+
this.register_hook('rcpt', 'my_rcpt')
|
|
341
|
+
}
|
|
342
|
+
```
|
|
358
343
|
|
|
359
|
-
|
|
360
|
-
which blocks access to certain globals and provides a global `server` object.
|
|
361
|
-
To access the `server` object, use `connection.server` instead.
|
|
344
|
+
### Deprecated plugin names
|
|
362
345
|
|
|
363
|
-
|
|
364
|
-
"Default Config and Overrides" section in [Config](Config.md).
|
|
346
|
+
Some plugin names have been folded into newer packages — for example `connect.fcrdns` is now `fcrdns`, `dnsbl` is now `dns-list`, and `rate_limit` / `max_unrecognized_commands` are now `limit`. Haraka logs a notice and loads the replacement automatically; the full mapping lives in `plugins.js → plugins.deprecated`.
|
|
365
347
|
|
|
366
348
|
## Shutdown
|
|
367
349
|
|
|
368
350
|
On graceful reload, Haraka will call a plugin's `shutdown` method.
|
|
369
351
|
|
|
370
|
-
This is so you can clear any timers or intervals, or shut down any connections
|
|
371
|
-
to remote servers. See [Issue 2024](https://github.com/haraka/Haraka/issues/2024).
|
|
352
|
+
This is so you can clear any timers or intervals, or shut down any connections to remote servers. See [Issue 2024](https://github.com/haraka/Haraka/issues/2024).
|
|
372
353
|
|
|
373
354
|
e.g.
|
|
374
355
|
|
|
@@ -378,9 +359,7 @@ exports.shutdown = function () {
|
|
|
378
359
|
}
|
|
379
360
|
```
|
|
380
361
|
|
|
381
|
-
If you don't implement this in your plugin and have a connection open or a
|
|
382
|
-
timer running then Haraka will take 30 seconds to shut down and have to
|
|
383
|
-
forcibly kill your process.
|
|
362
|
+
If you don't implement this in your plugin and have a connection open or a timer running then Haraka will take 30 seconds to shut down and have to forcibly kill your process.
|
|
384
363
|
|
|
385
364
|
Note: This only applies when running with a `nodes=...` value in smtp.ini.
|
|
386
365
|
|