===================
Email subscriptions
===================

Using the event subscribers in this package, Zope can send out
notification emails when an object has changed, for example for a
recipe:

  >>> from worldcookery.recipe import Recipe
  >>> cordon_bleu = Recipe()
  >>> cordon_bleu.name = u'Cordon bleu'
  >>> cordon_bleu.time_to_cook = 45
  >>> cordon_bleu.ingredients = [u'Ham', u'Cheese', 'Filet']
  >>> cordon_bleu.tools = [u'Tooth picks']
  >>> cordon_bleu.description = u'Hmm, cordon bleu!'

The recipients of such noficiation emails are stored in annotations.
We therefore have to make the object attribute annotatable:

  >>> from zope.interface import alsoProvides
  >>> from zope.annotation.interfaces import IAttributeAnnotatable
  >>> alsoProvides(cordon_bleu, IAttributeAnnotatable)

Without any subscribers, there will be no email sent, though:

  >>> from zope.event import notify
  >>> from zope.lifecycleevent import ObjectModifiedEvent
  >>> notify(ObjectModifiedEvent(cordon_bleu))

We first have to subscribe to the object (upon which a notification
email is already sent):

  >>> from worldcookery.mail.interfaces import IMailSubscriptions
  >>> subscriptions = IMailSubscriptions(cordon_bleu)
  >>> subscriptions.subscribe('chicken@worldcookery.com')
  Content-Type: ...
  ...

When we now send out an object modified event, the email subscriber
will send out an email that looks like this:

  >>> notify(ObjectModifiedEvent(cordon_bleu))
  Content-Type: text/plain; charset="utf-8"
  MIME-Version: 1.0
  Content-Transfer-Encoding: 7bit
  Subject: 'Cordon bleu' was modified
  From: notify@worldcookery.com
  To: chicken@worldcookery.com
  Date: ...
  <BLANKLINE>
  Name: Cordon bleu
  <BLANKLINE>
  Time to cook: 45
  <BLANKLINE>
  Ingredients:
  - Ham
  - Cheese
  - Filet
  <BLANKLINE>
  Necessary Kitchen Tools:
  - Tooth picks
  <BLANKLINE>
  Hmm, cordon bleu!
