350
350
connection = SMTPConnection() # Use default settings for connection
351
351
messages = get_notification_email()
352
352
connection.send_messages(messages)
354
Testing e-mail sending
355
----------------------
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
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::
368
python -m smtpd -n -c DebuggingServer localhost:1025
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.
375
For more entailed testing and processing of e-mails locally, see the Python
376
documentation on the `SMTP Server`_.
378
.. _SMTP Server: http://docs.python.org/library/smtpd.html