~launchpad-pqm/launchpad/devel

1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
1
Launchpad and Email
2
===================
3
4
Quickstart
5
----------
6
7
Create the file override-includes/+mail-configure.zcml with contents
8
similar to the following::
9
10
    <configure
11
        xmlns="http://namespaces.zope.org/zope"
12
        xmlns:mail="http://namespaces.zope.org/mail"
13
        i18n_domain="zope">
14
15
        <!-- delete the username and password attributes if you don't use
16
            SMTP auth -->
17
        <mail:smtpMailer
18
            name="smtp"
19
            hostname="localhost"
20
            port="25"
21
            username="biggus"
22
            password="dickus"
23
            />
24
25
        <mail:stubMailer
26
            name="stub"
27
            from_addr="stuart@stuartbishop.net"
28
            to_addr="stuart@stuartbishop.net"
29
            mailer="smtp"
30
            rewrite="false"
31
            />
32
3935.2.2 by Barry Warsaw
Added `mailer` attribute to `mail:mboxMailer` directive so that the message
33
        <mail:testMailer name="test-mailer" />
34
35
        <mail:mboxMailer
36
            name="mbox"
37
            filename="/tmp/launchpad.mbox"
38
            overwrite="true"
39
            mailer="test-mailer"
40
            />
41
42
    <!--
43
44
        Uncomment me if you want to get copies of emails in your normal inbox,
45
        via the stubMailer above.  However, tests will fail because they
46
        depend on using a directDelivery mailer.  See below.
47
48
        <mail:queuedDelivery
49
            mailer="stub"
50
            permission="zope.SendMail"
51
            queuePath="/var/tmp/launchpad_mailqueue" />
52
53
    -->
54
    <!--
55
56
        Uncomment me if you want to get test emails in a Unix mbox file, via
57
        the mboxMailer above.
58
59
        <mail:directDelivery
60
            mailer="mbox"
61
            permission="zope.SendMail"
62
            />
63
    -->
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
64
65
    </configure>
66
67
68
Options
69
-------
70
3935.2.2 by Barry Warsaw
Added `mailer` attribute to `mail:mboxMailer` directive so that the message
71
Zope3 provides two defined mailers out of the box (`smtp` and `sendmail`) so
72
most people won't actually need the `mail:smtpMailer` tag because the defaults
73
will usually just work.  However, several additional mailers are available for
74
you to use, depending on what you're trying to do.
75
76
The `mail:stubMailer` can be used to forward all emails to your normal inbox
77
via some other mailer.  Think of it as a proxy mailer that can be used to
78
specify explicit MAIL FROM and RCTP TO envelope addresses.  The `rewrite`
79
attribute of the `mail:stubMailer` specifies whether the RFC 2822 headers
80
should also be rewritten.  You and your spam filters might prefer this set to
81
`true`.
82
83
The `mail:mboxMailer` stores messages in a Unix mbox file and then forwards
84
the message on to another mailer.  You can use this if you want a record on
85
disk of all the messages sent, or if you'd rather not clutter up your inbox
86
with all your Launchpad test email.  The `overwrite` attribute says whether to
87
truncate the mbox file when Launchpad starts up (i.e. opens the file once in
88
'w' mode before appending all new messages to the file).
89
90
The `mail:testMailer` is necessary for the Launchpad tests to work.  You must
91
use a `mail:directDelivery` mailer for the tests, otherwise you'll get lots of
92
failures.  Basically, the testMailer stores the messages in a list in memory.
93
94
For both `mail:mboxMailer` and `mail:stubMailer` the `mailer` attribute
95
specifies the next mailer in the chain that the message will get sent to.
96
Thus if `mailer` is set to `smtp`, you'll get the messages in your inbox, but
97
if it's `test-mailer`, the unit tests will work.
98
99
Finally, these are all hooked up at the top with either a
100
`mail:queuedDelivery` section or a `mail:directDelivery` tag.  You must
101
use a `mail:directDelivery` tag if you want the unit tests to work because
102
otherwise, the in-memory list of the `mail:testMailer` won't be updated by the
103
time the unit test checks it.
104
105
If you just want the unit tests to work normally, don't include a
106
`mail:queuedDelivery` or a `mail:directDelivery` section at all.  Launchpad
107
will DTRT internally.  However, if you want copies in an mbox file or in your
108
inbox, set the `mailer` attribute to the appropriate mailer, chaining that to
109
a `mail:testMailer` for the unit tests or a `mail:smtpMailer` for
110
development.
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
111
112
113
API
114
---
115
116
Launchpad code should use the methods defined in canonical.launchpad.mail
117
to send emails (`simple_sendmail`, `sendmail` or possibly `raw_sendmail`)
118
119
120
Functional Tests
121
----------------
122
123
The functional test harness is configured to allow easy testing of
3935.2.2 by Barry Warsaw
Added `mailer` attribute to `mail:mboxMailer` directive so that the message
124
emails.  See `canonical/launchpad/mail/ftests/test_stub.py` for example
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
125
code.
126
127
128
Details
129
-------
130
131
To send email from Zope3, you use an `IMailDelivery` Utility, which
132
defines a single `send` method. There are two standard `IMailDelivery`
133
implementations:
3935.2.2 by Barry Warsaw
Added `mailer` attribute to `mail:mboxMailer` directive so that the message
134
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
135
    1. `QueuedDelivery` -- email is delivered in a seperate thread. We use
136
        this for production.
137
138
    2. `DirectDelivery` -- email is send synchronously during transaction
3935.2.2 by Barry Warsaw
Added `mailer` attribute to `mail:mboxMailer` directive so that the message
139
        commit.  We use this for tests.
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
140
3935.2.2 by Barry Warsaw
Added `mailer` attribute to `mail:mboxMailer` directive so that the message
141
Both implementations will send no email if the transaction is aborted.  Both
142
implementations use events to notify anything that cares to subscribe if
143
delivery succeeded or failed.  Both implementations look up an `IMailer`
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
144
utility by name to do the actual delivery, as specified in the `mailer`
145
attribute of the `queuedDelivery` and `directDelivery` ZCML tags.
146
147
Zope3 provides two `IMailer` implementations out of the box:
148
149
    1. `SMTPMailer` -- sends email using SMTP
150
151
    2. `SendmailMailer1 -- Uses the `sendmail` program to send email.
152
3935.2.2 by Barry Warsaw
Added `mailer` attribute to `mail:mboxMailer` directive so that the message
153
In addition to these two, there are three more `IMailer` implementations
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
154
for use with Launchpad development (production instances will just use
155
`SMTPMailer` or `SendmailMailer`):
156
3935.2.2 by Barry Warsaw
Added `mailer` attribute to `mail:mboxMailer` directive so that the message
157
    3. StubMailer -- rewrites the envelope headers and optionally the RFC 2822
158
       To and From headers before handing on to a different `IMailer`.
159
160
    4. TestMailer -- stores the email in memory in a Python list object called
161
       `canonical.launchpad.mail.stub.test_email` for easy access by unit
162
       tests.
163
164
    5. MboxMailer -- stores the email in a Unix mbox file before optionally
3935.2.8 by Barry Warsaw
Address spiv's review comments.
165
       handing the message off to another `IMailer`.
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
166
3691.394.1 by Barry Warsaw
Trivial documentation fixes.
167
Developers (and production and dogfood server, until we are confident
168
messaging is working fine) should use the StubMailer, like in the quickstart
169
example.  This causes all emails to be redirected to the specified destination
170
address to you can test to your hearts content without spamming other
3935.2.2 by Barry Warsaw
Added `mailer` attribute to `mail:mboxMailer` directive so that the message
171
developers or innocent civilians.  Or you can use the MboxMailer.
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
172
173
The functional test suite is already configured to use the TestMailer.
3935.2.2 by Barry Warsaw
Added `mailer` attribute to `mail:mboxMailer` directive so that the message
174
However, if you use a StubMailer or MboxMailer and want the test suite to
175
work, you must hook it up to a TestMailer explicitly.  See
176
`canonical/launchpad/mail/ftests/test_stub.py` for an example showing how
177
functional tests can check that notifications are being sent correctly.