repoze.sendmail
raw JSON → 4.4.1 verified Fri May 01 auth: no python
A Python library for sending email via SMTP or a queued delivery mechanism. Provides a transaction-aware mail delivery interface with support for multiple delivery modes. Current version 4.4.1, stable but infrequently updated.
pip install repoze.sendmail Common errors
error AttributeError: module 'repoze.sendmail' has no attribute 'delivery' ↓
cause Incorrect import path. The module is 'repoze.sendmail.delivery', not 'repoze.sendmail.delivery' (yes it's confusing).
fix
Use 'from repoze.sendmail.delivery import ...'
error NameError: name 'SMTPMailer' is not defined ↓
cause Forgot to import SMTPMailer from the correct submodule.
fix
Add: 'from repoze.sendmail.mailer import SMTPMailer'
error TypeError: send() takes 3 positional arguments but 4 were given ↓
cause The send method expects (from_addr, to_addrs, message). You may have passed an extra argument like subject as separate.
fix
Build the message as a bytes object or email message and pass it as the third argument.
Warnings
breaking In version 4.0, the import path for mailer classes changed. The old repoze.sendmail.mailer module was split into separate classes. ↓
fix Update imports: from repoze.sendmail.mailer import SMTPMailer instead of the old alias.
deprecated The use of the 'mailer_factory' function is deprecated. Use DirectMailDelivery or QueuedMailDelivery directly. ↓
fix Replace mailer_factory calls with explicit delivery class instantiation.
gotcha The library requires the 'transaction' package for queued delivery. If you don't use a transaction manager, the message may not be delivered until the transaction commits. ↓
fix Ensure you have a transaction manager (e.g., Zope or pyramid_tm) when using QueuedMailDelivery.
Imports
- mailer_factory wrong
from repoze.sendmail import mailer_factorycorrectfrom repoze.sendmail.delivery import DirectMailDelivery - QueuedMailDelivery wrong
from repoze.sendmail.queued import QueuedMailDeliverycorrectfrom repoze.sendmail.delivery import QueuedMailDelivery
Quickstart
from repoze.sendmail.delivery import DirectMailDelivery
from repoze.sendmail.mailer import SMTPMailer
mailer = SMTPMailer(hostname='localhost', port=25)
delivery = DirectMailDelivery(mailer)
from_addr = 'sender@example.com'
to_addrs = ['recipient@example.com']
msg = b'Subject: Test\n\nHello!'
delivery.send(from_addr, to_addrs, msg)