Asynchronous SMTP Mail sender inspired from Zope 3
Background
CPSMailAccess let the user configure the SMTP server he or she wants to use.
It can be the same SMTP server for all users, or a different one for each
user. Having multiple configuration can sound overkill, but since the
application let you browse any mailbox, you might need to associate a
different SMTP server to each MailBox
What Zope 3 provides
Zope 3 introduces a pretty cool mechanism: a delivery queue that writes
mails into a filesystem dir (a MailDir in fact) and let a thread send them
asynchronously.
This is rock-solid, since :
- the work can restart even if Zope hangs: no send will be lost
- the user does not wait
that’s exactly what’s needeed for large scale intranets. The pattern used
is:
- MailWriter: writes mails into the folder
- MailReader: thread, sends mails found into the folder
- MailSender: interface,provide a send method that calls MailWriter, and
creates the MailDir
Special headers are inserted in the mail, so extra informations can be
shared between the MailWriter and the MailSender.
What CPSMailAccess needs
The only missing feature for CPSMailAccess is to add the SMTP host and port
informations into mails that are written into the MailDir.
Those are read by the sender and removed before the mail is sent.
The beta 2 version will include this feature, with a
MailWriter-MailReader-MailSender pattern derived from Zope 3 classes.
And thanks to Zope 3 pythonic style, this module can be used in any Python
application.
(Post originally written by Tarek Ziadé on the old Nuxeo blogs.)