1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
|
===============
Outgoing runner
===============
The outgoing runner is the process that delivers messages to the directly
upstream SMTP server. It is this upstream SMTP server that performs final
delivery to the intended recipients.
Messages that appear in the outgoing queue are processed individually through
a *delivery module*, essentially a pluggable interface for determining how the
recipient set will be batched, whether messages will be personalized and
VERP'd, etc. The outgoing runner doesn't itself support retrying but it can
move messages to the 'retry queue' for handling delivery failures.
::
>>> mlist = create_list('test@example.com')
>>> from mailman.testing.helpers import subscribe
>>> subscribe(mlist, 'Anne')
<Member: Anne Person <aperson@example.com>
on test@example.com as MemberRole.member>
>>> subscribe(mlist, 'Bart')
<Member: Bart Person <bperson@example.com>
on test@example.com as MemberRole.member>
>>> subscribe(mlist, 'Cris')
<Member: Cris Person <cperson@example.com>
on test@example.com as MemberRole.member>
Normally, messages would show up in the outgoing queue after the message has
been processed by the rule set and pipeline. But we can simulate that here by
injecting a message directly into the outgoing queue. First though, we must
call the ``member-recipients`` handler so that the message metadata will be
populated with the list of addresses to deliver the message to.
::
>>> msg = message_from_string("""\
... From: aperson@example.com
... To: test@example.com
... Subject: My first post
... Message-ID: <first>
...
... First post!
... """)
>>> msgdata = {}
>>> handler = config.handlers['member-recipients']
>>> handler.process(mlist, msg, msgdata)
>>> outgoing_queue = config.switchboards['out']
The ``to-outgoing`` handler populates the message metadata with the
destination mailing list name. Simulate that here too.
>>> ignore = outgoing_queue.enqueue(
... msg, msgdata,
... tolist=True,
... listid=mlist.list_id)
Running the outgoing runner processes the message, delivering it to the
upstream SMTP.
>>> from mailman.runners.outgoing import OutgoingRunner
>>> from mailman.testing.helpers import make_testable_runner
>>> outgoing = make_testable_runner(OutgoingRunner, 'out')
>>> outgoing.run()
Every recipient got the same copy of the message.
::
>>> messages = list(smtpd.messages)
>>> len(messages)
1
>>> print(messages[0].as_string())
From: aperson@example.com
To: test@example.com
Subject: My first post
Message-ID: <first>
X-Peer: ...
X-MailFrom: test-bounces@example.com
X-RcptTo: aperson@example.com, bperson@example.com, cperson@example.com
<BLANKLINE>
First post!
Personalization
===============
Mailman supports sending individual messages to each recipient by
personalizing delivery. This increases the bandwidth between Mailman and the
upstream mail server, and between the upstream mail server and the remote
recipient mail servers. The benefit is that personalization provides for a
much better user experience, because the messages can be tailored for each
recipient.
>>> from mailman.interfaces.mailinglist import Personalization
>>> mlist.personalize = Personalization.individual
>>> transaction.commit()
Now when we send the message, our mail server will get three copies instead of
just one.
>>> ignore = outgoing_queue.enqueue(
... msg, msgdata,
... listid=mlist.list_id)
>>> outgoing.run()
>>> messages = list(smtpd.messages)
>>> len(messages)
3
Since we've done no other configuration, the only difference in the messages
is the recipient address. Specifically, the Sender header is the same for all
recipients.
::
>>> from operator import itemgetter
>>> def show_headers(messages):
... for message in sorted(messages, key=itemgetter('x-rcptto')):
... print(message['X-RcptTo'], message['X-MailFrom'])
>>> show_headers(messages)
aperson@example.com test-bounces@example.com
bperson@example.com test-bounces@example.com
cperson@example.com test-bounces@example.com
VERP
====
An even more interesting personalization opportunity arises if VERP_ is
enabled. Here, Mailman takes advantage of the fact that it's sending
individualized messages anyway, so it also encodes the recipients address in
the Sender header.
.. _VERP: ../../mta/docs/verp.html
Forcing VERP
------------
A handler can force VERP by setting the ``verp`` key in the message metadata.
::
>>> ignore = outgoing_queue.enqueue(
... msg, msgdata,
... verp=True,
... listid=mlist.list_id)
>>> outgoing.run()
>>> messages = list(smtpd.messages)
>>> len(messages)
3
>>> show_headers(messages)
aperson@example.com test-bounces+aperson=example.com@example.com
bperson@example.com test-bounces+bperson=example.com@example.com
cperson@example.com test-bounces+cperson=example.com@example.com
VERP personalized deliveries
----------------------------
The site administrator can enable VERP whenever messages are personalized.
>>> config.push('verp', """
... [mta]
... verp_personalized_deliveries: yes
... """)
Again, we get three individual messages, with VERP'd ``Sender`` headers.
::
>>> ignore = outgoing_queue.enqueue(
... msg, msgdata,
... listid=mlist.list_id)
>>> outgoing.run()
>>> messages = list(smtpd.messages)
>>> len(messages)
3
>>> show_headers(messages)
aperson@example.com test-bounces+aperson=example.com@example.com
bperson@example.com test-bounces+bperson=example.com@example.com
cperson@example.com test-bounces+cperson=example.com@example.com
>>> config.pop('verp')
>>> mlist.personalize = Personalization.none
>>> transaction.commit()
VERP every once in a while
--------------------------
Perhaps personalization is too much of an overhead, but the list owners would
still like to occasionally get the benefits of VERP. The site administrator
can enable occasional VERPing of messages every so often, by setting a
delivery interval. Every N non-personalized deliveries turns on VERP for just
the next one.
::
>>> config.push('verp occasionally', """
... [mta]
... verp_delivery_interval: 3
... """)
# Reset the list's post_id, which is used to calculate the intervals.
>>> mlist.post_id = 1
>>> transaction.commit()
The first message is sent to the list, and it is neither personalized nor
VERP'd.
::
>>> ignore = outgoing_queue.enqueue(
... msg, msgdata,
... listid=mlist.list_id)
>>> outgoing.run()
>>> messages = list(smtpd.messages)
>>> len(messages)
1
>>> show_headers(messages)
aperson@example.com, bperson@example.com, cperson@example.com
test-bounces@example.com
# Perform post-delivery bookkeeping.
>>> after = config.handlers['after-delivery']
>>> after.process(mlist, msg, msgdata)
>>> transaction.commit()
The second message sent to the list is also not VERP'd.
::
>>> ignore = outgoing_queue.enqueue(
... msg, msgdata,
... listid=mlist.list_id)
>>> outgoing.run()
>>> messages = list(smtpd.messages)
>>> len(messages)
1
>>> show_headers(messages)
aperson@example.com, bperson@example.com, cperson@example.com
test-bounces@example.com
# Perform post-delivery bookkeeping.
>>> after.process(mlist, msg, msgdata)
>>> transaction.commit()
The third message though is VERP'd.
::
>>> ignore = outgoing_queue.enqueue(
... msg, msgdata,
... listid=mlist.list_id)
>>> outgoing.run()
>>> messages = list(smtpd.messages)
>>> len(messages)
3
>>> show_headers(messages)
aperson@example.com test-bounces+aperson=example.com@example.com
bperson@example.com test-bounces+bperson=example.com@example.com
cperson@example.com test-bounces+cperson=example.com@example.com
# Perform post-delivery bookkeeping.
>>> after.process(mlist, msg, msgdata)
>>> transaction.commit()
The next one is back to bulk delivery.
::
>>> ignore = outgoing_queue.enqueue(
... msg, msgdata,
... listid=mlist.list_id)
>>> outgoing.run()
>>> messages = list(smtpd.messages)
>>> len(messages)
1
>>> show_headers(messages)
aperson@example.com, bperson@example.com, cperson@example.com
test-bounces@example.com
>>> config.pop('verp occasionally')
VERP every time
---------------
If the site administrator wants to enable VERP for every delivery, even if no
personalization is going on, they can set the interval to 1.
::
>>> config.push('always verp', """
... [mta]
... verp_delivery_interval: 1
... """)
# Reset the list's post_id, which is used to calculate the intervals.
>>> mlist.post_id = 1
>>> transaction.commit()
The first message is VERP'd.
::
>>> ignore = outgoing_queue.enqueue(
... msg, msgdata,
... listid=mlist.list_id)
>>> outgoing.run()
>>> messages = list(smtpd.messages)
>>> len(messages)
3
>>> show_headers(messages)
aperson@example.com test-bounces+aperson=example.com@example.com
bperson@example.com test-bounces+bperson=example.com@example.com
cperson@example.com test-bounces+cperson=example.com@example.com
# Perform post-delivery bookkeeping.
>>> after.process(mlist, msg, msgdata)
>>> transaction.commit()
As is the second message.
::
>>> ignore = outgoing_queue.enqueue(
... msg, msgdata,
... listid=mlist.list_id)
>>> outgoing.run()
>>> messages = list(smtpd.messages)
>>> len(messages)
3
>>> show_headers(messages)
aperson@example.com test-bounces+aperson=example.com@example.com
bperson@example.com test-bounces+bperson=example.com@example.com
cperson@example.com test-bounces+cperson=example.com@example.com
# Perform post-delivery bookkeeping.
>>> after.process(mlist, msg, msgdata)
>>> transaction.commit()
And the third message.
::
>>> ignore = outgoing_queue.enqueue(
... msg, msgdata,
... listid=mlist.list_id)
>>> outgoing.run()
>>> messages = list(smtpd.messages)
>>> len(messages)
3
>>> show_headers(messages)
aperson@example.com test-bounces+aperson=example.com@example.com
bperson@example.com test-bounces+bperson=example.com@example.com
cperson@example.com test-bounces+cperson=example.com@example.com
# Perform post-delivery bookkeeping.
>>> after.process(mlist, msg, msgdata)
>>> transaction.commit()
>>> config.pop('always verp')
Never VERP
----------
Similarly, the site administrator can disable occasional VERP'ing of
non-personalized messages by setting the interval to zero.
::
>>> config.push('never verp', """
... [mta]
... verp_delivery_interval: 0
... """)
# Reset the list's post_id, which is used to calculate the intervals.
>>> mlist.post_id = 1
>>> transaction.commit()
Neither the first message...
::
>>> ignore = outgoing_queue.enqueue(
... msg, msgdata,
... listid=mlist.list_id)
>>> outgoing.run()
>>> messages = list(smtpd.messages)
>>> len(messages)
1
>>> show_headers(messages)
aperson@example.com, bperson@example.com, cperson@example.com
test-bounces@example.com
...nor the second message is VERP'd.
::
>>> ignore = outgoing_queue.enqueue(
... msg, msgdata,
... listid=mlist.list_id)
>>> outgoing.run()
>>> messages = list(smtpd.messages)
>>> len(messages)
1
>>> show_headers(messages)
aperson@example.com, bperson@example.com, cperson@example.com
test-bounces@example.com
|