~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
13668.1.23 by Curtis Hovey
Fixed imports that relied on globs.
116
Launchpad code should use the methods defined in lp.services.mail.sendmail
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
117
to send emails (`simple_sendmail`, `sendmail` or possibly `raw_sendmail`)
118
119
120
Functional Tests
121
----------------
122
13697.10.1 by Gavin Panella
Update mailer documentation.
123
The functional test harness is configured to allow easy testing of emails.
124
See `lp/services/mail/tests/test_stub.py` for example code.
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
125
126
127
Details
128
-------
129
130
To send email from Zope3, you use an `IMailDelivery` Utility, which
131
defines a single `send` method. There are two standard `IMailDelivery`
132
implementations:
3935.2.2 by Barry Warsaw
Added `mailer` attribute to `mail:mboxMailer` directive so that the message
133
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
134
    1. `QueuedDelivery` -- email is delivered in a seperate thread. We use
13697.10.1 by Gavin Panella
Update mailer documentation.
135
       this for production.
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
136
137
    2. `DirectDelivery` -- email is send synchronously during transaction
13697.10.1 by Gavin Panella
Update mailer documentation.
138
       commit.  We use this for tests.
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
139
3935.2.2 by Barry Warsaw
Added `mailer` attribute to `mail:mboxMailer` directive so that the message
140
Both implementations will send no email if the transaction is aborted.  Both
141
implementations use events to notify anything that cares to subscribe if
142
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
143
utility by name to do the actual delivery, as specified in the `mailer`
144
attribute of the `queuedDelivery` and `directDelivery` ZCML tags.
145
146
Zope3 provides two `IMailer` implementations out of the box:
147
148
    1. `SMTPMailer` -- sends email using SMTP
149
150
    2. `SendmailMailer1 -- Uses the `sendmail` program to send email.
151
3935.2.2 by Barry Warsaw
Added `mailer` attribute to `mail:mboxMailer` directive so that the message
152
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
153
for use with Launchpad development (production instances will just use
154
`SMTPMailer` or `SendmailMailer`):
155
13697.10.1 by Gavin Panella
Update mailer documentation.
156
    3. `StubMailer` -- rewrites the envelope headers and optionally the RFC
157
       2822 To and From headers before handing on to a different `IMailer`.
3935.2.2 by Barry Warsaw
Added `mailer` attribute to `mail:mboxMailer` directive so that the message
158
13697.10.1 by Gavin Panella
Update mailer documentation.
159
    4. `TestMailer` -- stores the email in memory in a Python list object
160
       called `lp.services.mail.stub.test_email` for easy access by unit
3935.2.2 by Barry Warsaw
Added `mailer` attribute to `mail:mboxMailer` directive so that the message
161
       tests.
162
13697.10.1 by Gavin Panella
Update mailer documentation.
163
    5. `MboxMailer` -- stores the email in a Unix mbox file before optionally
3935.2.8 by Barry Warsaw
Address spiv's review comments.
164
       handing the message off to another `IMailer`.
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
165
3691.394.1 by Barry Warsaw
Trivial documentation fixes.
166
Developers (and production and dogfood server, until we are confident
167
messaging is working fine) should use the StubMailer, like in the quickstart
168
example.  This causes all emails to be redirected to the specified destination
169
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
170
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
171
172
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
173
However, if you use a StubMailer or MboxMailer and want the test suite to
174
work, you must hook it up to a TestMailer explicitly.  See
13697.10.1 by Gavin Panella
Update mailer documentation.
175
`lp/services/mail/tests/test_stub.py` for an example showing how functional
176
tests can check that notifications are being sent correctly.