repoze.sendmail

Repoze Sendmail
Download

repoze.sendmail Ranking & Summary

Advertisement

  • Rating:
  • License:
  • ZPL
  • Publisher Name:
  • Chris Rossi
  • Publisher web site:
  • http://www.repoze.org

repoze.sendmail Tags


repoze.sendmail Description

Repoze Sendmail repoze.sendmail is a Python module that allows coupling the sending of email messages with a transaction, using the Zope transaction manager. This allows messages to only be sent out when and if a transaction is committed, preventing users from receiving notifications about events which may not have completed successfully. Messages may be sent directly or stored in a queue for later sending. The queued mail approach is the more common and recommended path. A console application which can flush the queue, sending the messages that it finds, is included for convenience.repoze.sendmail is a fork of zope.sendmail. Functionality that was specific to running in a Zope context has been removed, making this version more generally useful to users of other frameworks.Note that repoze.sendmail works only under Python 2.5+ (it will not work under 2.4).Basic TutorialMessages are sent by means of a Delivery object. Two deliveries are included in repoze.sendmail.delivery: QueuedMailDelivery and DirectMailDelivery. A delivery implements the interface defined by repoze.sendmail.interfaces.IDelivery, which consists of a single send method:def send(fromaddr, toaddrs, message): """ Sends message on transaction commit. """fromaddr is the address of the sender of the message. toaddrs is a list of email addresses for recipients of the message. message must be an instance email.message.Message and is the actual message which will be sent.To create a queued delivery:from email.message import Messagefrom repoze.sendmail.delivery import QueuedMailDeliverymessage = Message()message = 'Chris < chris@example.com >'message = 'Paul , Tres < tres@example.com >'message = "repoze.sendmail is a useful package"message.set_payload("The subject line says it all.")delivery = QueuedMailDelivery('path/to/queue')delivery.send('chris@example.com', , message)The message will be added to the maildir queue in 'path/to/queue' when and if the current transaction is committed successsfully.repoze.sendmail includes a console app utility for sending queued messages:bin/qp path/to/queueThis will attempt to use an SMTP server at localhost to send any messages found in the queue. To see all options available:bin/qp --helpDirect delivery can also be used:from repoze.sendmail.delivery import DirectMailDeliveryfrom repoze.sendmail.mailer import SMTPMailermailer = SMTPMailer() # Uses localhost, port 25 be default.delivery = DirectMailDelivery(mailer)delivery.send('chris@example.com', , message)repoze.sendmail hooks into the Zope transaction manager and only sends 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 transactiontransaction.manager.begin()try: my_code_here() transaction.manager.commit()except e: transaction.manager.abort() raise e Requirements: · Python What's New in This Release: · Queued delivery now creates a copy of the passed in messsage before adding the 'X-Actually-{To,From}' headers. This avoids rudely mutating the message being sent in ways that might not be expected by the sender. (LP #780000)


repoze.sendmail Related Software