pyramid_mailer

raw JSON →
0.15.1 verified Fri May 01 auth: no python maintenance

A library for sending email from Pyramid web applications. It wraps Python's smtplib and provides a simple API to send email messages with attachments, CC, BCC, and more. Version 0.15.1 is the latest release, but the project appears unmaintained since 2016.

pip install pyramid-mailer
error AttributeError: module 'pyramid_mailer' has no attribute 'Message'
cause Importing Message from the wrong path. The correct import is from pyramid_mailer.message import Message.
fix
Use 'from pyramid_mailer.message import Message' instead of 'from pyramid_mailer import Message'.
error TypeError: __init__() missing 1 required positional argument: 'sender'
cause The Message constructor requires a 'sender' argument to be passed.
fix
Provide a 'sender' argument, e.g., Message(subject='...', sender='me@example.com', ...).
error ConnectionRefusedError: [Errno 111] Connection refused
cause The SMTP server is not reachable or the host/port configuration is incorrect (defaults to localhost:25).
fix
Configure the correct SMTP host and port in your .ini file (e.g., mail.host = smtp.example.com, mail.port = 587) and ensure credentials are set if needed.
gotcha The Message class requires the 'sender' argument; it's not optional. Many users forget to set it and get a TypeError.
fix Always provide a 'sender' parameter (email string) when creating a Message.
gotcha Mailer.send does not return a boolean or raise on failure; it delegates to the mailer backend (repoze.sendmail). Errors may be silently swallowed if the mail host is unreachable.
fix Wrap mailer.send in try/except or configure logging to capture backend exceptions.
deprecated pyramid_mailer uses repoze.sendmail which has been unmaintained and may have issues with newer Python versions or TLS/SSL configurations.
fix Consider switching to a more modern alternative like mailjet, sendgrid, or use smtplib directly.

Basic usage of pyramid_mailer: create a Mailer from a request, construct a Message, and send.

from pyramid.config import Configurator
from pyramid_mailer.mailer import Mailer
from pyramid_mailer.message import Message

config = Configurator()
# Configure mailer (e.g., default mail.host via ini file or override)
config.include('pyramid_mailer')

# In a view callable:
request = config.registry['request']  # Example
mailer = Mailer(request)
msg = Message(subject='Hello',
              sender='from@example.com',
              recipients=['to@example.com'],
              body='Test email')
mailer.send(msg)