Repoze Sendmail
Project description
repoze.sendmail
repoze.sendmail is a fork of zope.sendmail with dependency on zope security framework removed. The idea being that in this case authorization should be handled by caller, not by this library, which simply provides a means to send email. This fork is meant to be usable with repoze.bfg and other non-Zope3 frameworks.
We have also made optional, for queued delivery, the running of the queue processor thread. We have added a console script, qp, which can process queued mail and either exit after one pass or continue to run daemonically, checking the queue periodically.
You probably want to take a look at the documentation for zope.sendmail:
http://pypi.python.org/pypi/zope.sendmail
See also src/repoze/sendmail/README.txt
Basic Tutorial
To use repoze.sendmail using the component architecture, you’ll need to add something like this to your project’s zcml:
Note that the queuePath in the queuedDelivery must exist on the filesystem. This creates two utilities, a mailer, named smtp, and a delivery, named myapp.mailer. The mailer is used by the delivery mechanism, so generally in your code you need only look up the delivery utility:
def send_email(msg): mailer = getUtility(IMailDelivery, 'bfgtest.mailer') mailer.send(sender, [recipient], msg.as_string())
The message is an instance of email.MIMEText.MIMEText:
import email.MIMEText def create_message(sender, recipient, subject, body): msg = email.MIMEText.MIMEText(body.encode('UTF-8'), 'plain', 'UTF-8') msg["From"] = sender msg["To"] = recipient msg["Subject"] = email.Header.Header(subject, 'UTF-8') return msg
repoze.sendmail hooks into the transaction system and only sends queued messages on transaction commit. If you are using a framework which, like repoze.bfg, does not use transactions by default, you will need to begin and commit a transaction of your own in order for mail to be sent:
import transaction transaction.manager.begin() try: my_code_here() transaction.manager.commit() except e: transaction.manager.abort() raise e
Change history
1.2 (2010-02-11)
Maildir storage for queue can now handle unicode passed in for message or to/from addresses.
1.1 (2009-02-24)
Added logging to queue processor console app.
Added ini config parsing to queue processor console app.
1.0.0
Initial release
Copy of zope.sendmail with dependency on security removed.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.