LogoLogo
Official SiteAPI Reference
stable/3.0
stable/3.0
  • Cement Developer Guide
  • Release Information
    • What's New!
    • Upgrading
    • ChangeLog
    • Deprecations
  • Getting Started
    • Installation
    • Developer Tools
    • Framework Overview
    • Beginner Tutorial
      • Part 1: Creating Your First Project
      • Part 2: Adding Features
      • Part 3: Extending a Project
      • Part 4: Making Everything Legit
  • Core Foundation
    • Interfaces and Handlers
    • Hooks
    • Configuration Settings
    • Arguments
    • Logging
    • Controllers
    • Output Rendering
    • Caching
    • Mail Messaging
    • Framework Extensions
    • Application Plugins
    • Templating
  • Utilities
    • Filesystem
    • Shell
    • Miscellaneous
  • Extensions
    • Alarm
    • Argparse
    • Colorlog
    • ConfigParser
    • Daemon
    • Dummy
    • Generate
    • Jinja2
    • Json
    • Logging
    • Memcached
    • Mustache
    • Plugin
    • Print
    • Redis
    • Scrub
    • SMTP
    • Tabulate
    • Yaml
    • Watchdog
  • Additional Topics
    • Extending The App Object
    • Unit Testing
    • Cleanup
    • Signal Handling
    • Pipenv
    • Autocomplete
    • Profiling with cProfile
    • Debugging with VSCode
  • Environment Variables
  • Terminology
  • Contributing
  • Privacy Policy
Powered by GitBook
On this page
  • Introduction to the Mail Interface
  • Configuration
  • Application Meta Options
  • Working with Mail Messages
  • Creating a Mail Handler
  1. Core Foundation

Mail Messaging

PreviousCachingNextFramework Extensions

Last updated 6 years ago

Introduction to the Mail Interface

Cement defines a , as well as the default that implements the interface as a placeholder but does not actually send any mail.

Cement often includes multiple handler implementations of an interface that may or may not have additional features or functionality than the interface requires. The documentation below only references usage based on the interface and default handler (not the full capabilities of an implementation).

Cement Extensions that Provide Mail Handlers:

  • (default)

API References:

Configuration

Application Meta Options

The following options under modify configuration handling:

Option

Description

mail_handler

The handler that implements the mail interface.

Working with Mail Messages

from cement import App

with App('myapp') as app:
    app.run()

    # send a message using the defined mail handler
    app.mail.send("Test mail message",
                  subject='My Subject',
                  to=['me@example.com'],
                  from_addr='noreply@localhost',
                  )
python myapp.py

=============================================================================
DUMMY MAIL MESSAGE
-----------------------------------------------------------------------------

To: me@example.com
From: noreply@localhost
CC:
BCC:
Subject: My Subject

---

Test mail message

-----------------------------------------------------------------------------

Creating a Mail Handler

myapp.py
from cement import App
from cement.core.mail import MailHandler

class MyMailHandler(MailHandler):
    class Meta:
        label = 'my_mail_handler'

    # do something to implement the interface

class MyApp(App):
    class Meta:
        label = 'myapp'
        mail_handler = 'my_mail_handler'
        handlers = [
            MyMailHandler,
        ]

The default dummy mail handler simply prints the message to console, and does not send anything. You can override the mail handler via App.Meta.mail_handler, for example using the .

All interfaces in Cement can be overridden with your own implementation. This can be done either by sub-classing itself, or by sub-classing an existing extension's handlers in order to alter their functionality.

Mail Interface
DummyMailHandler
Dummy
SMTP
Cement Core Mail Module
App.Meta
SMTP Extension
MailHandler