summaryrefslogtreecommitdiff
path: root/src/mailman/queue/docs/outgoing.txt
blob: 6722dee8442b77d5685db912aab640628f7f60a8 (plain)
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
Outgoing queue runner
=====================

The outgoing queue runner is the process that delivers messages to the
directly upstream SMTP server.  It is this external 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.

    >>> from mailman.app.lifecycle import create_list
    >>> mlist = create_list(u'test@example.com')

    >>> from mailman.app.membership import add_member
    >>> from mailman.interfaces.member import DeliveryMode
    >>> add_member(mlist, u'aperson@example.com', u'Anne Person',
    ...            u'password', DeliveryMode.regular, u'en')
    >>> add_member(mlist, u'bperson@example.com', u'Bart Person',
    ...            u'password', DeliveryMode.regular, u'en')
    >>> add_member(mlist, u'cperson@example.com', u'Cris Person',
    ...            u'password', DeliveryMode.regular, u'en')

By setting the mailing list to personalize messages, each recipient will get a
unique copy of the message, with certain headers tailored for that recipient.

    >>> from mailman.interfaces.mailinglist import Personalization
    >>> mlist.personalize = Personalization.individual
    >>> commit()

    >>> msg = message_from_string("""\
    ... From: aperson@example.com
    ... To: test@example.com
    ... Subject: My first post
    ... Message-ID: <first>
    ...
    ... First post!
    ... """)

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.

    >>> msgdata = {}
    >>> handler = config.handlers['calculate-recipients']
    >>> handler.process(mlist, msg, msgdata)

    >>> outgoing_queue = config.switchboards['out']
    >>> ignore = outgoing_queue.enqueue(
    ...     msg, msgdata,
    ...     verp=True, listname=mlist.fqdn_listname, tolist=True,
    ...     _plaintext=True)

Running the outgoing queue runner processes the message, delivering it to the
upstream SMTP, which happens to be our test server.

    >>> from mailman.queue.outgoing import OutgoingRunner
    >>> from mailman.testing.helpers import make_testable_runner
    >>> outgoing = make_testable_runner(OutgoingRunner, 'out')
    >>> outgoing.run()

Three messages have been delivered to our SMTP server, one for each recipient.

    >>> from operator import itemgetter
    >>> messages = sorted(smtpd.messages, key=itemgetter('sender'))
    >>> len(messages)
    3

    >>> for message in messages:
    ...     print message['sender']
    test-bounces+aperson=example.com@example.com
    test-bounces+bperson=example.com@example.com
    test-bounces+cperson=example.com@example.com