~ubuntu-branches/ubuntu/saucy/python-django/saucy-updates

« back to all changes in this revision

Viewing changes to docs/topics/email.txt

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lamb
  • Date: 2009-07-29 11:26:28 UTC
  • mfrom: (1.2.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: james.westby@ubuntu.com-20090729112628-9qrzwnl9x32jxhbg
Tags: upstream-1.1
ImportĀ upstreamĀ versionĀ 1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
350
350
    connection = SMTPConnection()   # Use default settings for connection
351
351
    messages = get_notification_email()
352
352
    connection.send_messages(messages)
 
353
 
 
354
Testing e-mail sending
 
355
----------------------
 
356
 
 
357
The are times when you do not want Django to send e-mails at all. For example,
 
358
while developing a website, you probably don't want to send out thousands of
 
359
e-mails -- but you may want to validate that e-mails will be sent to the right
 
360
people under the right conditions, and that those e-mails will contain the
 
361
correct content.
 
362
 
 
363
The easiest way to test your project's use of e-mail is to use a "dumb" e-mail
 
364
server that receives the e-mails locally and displays them to the terminal,
 
365
but does not actually send anything. Python has a built-in way to accomplish
 
366
this with a single command::
 
367
 
 
368
    python -m smtpd -n -c DebuggingServer localhost:1025
 
369
 
 
370
This command will start a simple SMTP server listening on port 1025 of
 
371
localhost. This server simply prints to standard output all email headers and
 
372
the email body. You then only need to set the :setting:`EMAIL_HOST` and
 
373
:setting:`EMAIL_PORT` accordingly, and you are set.
 
374
 
 
375
For more entailed testing and processing of e-mails locally, see the Python
 
376
documentation on the `SMTP Server`_.
 
377
 
 
378
.. _SMTP Server: http://docs.python.org/library/smtpd.html