Skip to main content

An easy way to send emails in Python

Project description

# simplemail

## Overview
**simplemail** is an easy way to send emails in Python. It will use a sendmail binary which is almost always available and ready to go.

## Dependencies
- Python 2.6 or 2.7

## Sample usecase
The code has docstrings which explains how to use the library. But here's the sample usecase I just made up for showing you the benefits and simplicity of using it.

Let's assume that you have a general announcement which you would like to send out to your mailing list. The message itself is common for every member of your list, but you want to greet every person by his or her name in the beginning of your message.

So you have a list of your customer in a dictionary.

from simplemail import Simplemail

mailinglist = {"Bob": "bob@domain.tld",
"Alice": "alice@domain.tld"}

Let's fire the default settings for all our emails.

message = Simplemail(sender="Maillist Owner <postmaster@domain.tld>",
subject="Monthly announcement")

Next you are going to write a default message body for everyone.

body = "We are proudly to present our new feature."

Let's compose a personal greeting for every member of your list and fire an email.

for person in mailinglist.keys():
gr = "Hello, %s\n\n%s" % (person, body)
message.send(recipient=mailinglist[person], body=gr)

Now you have a personal greeting for all of your subscribers.

## Logging handler
There is a special logging handler which utilizes the simplemail library. Here's a code sample:

import logging
from simplemail import Simplemail
from simplemail.handlers import SimplemailLogger

# Initializing Simplemail
mail = Simplemail(sender="Application Error <errors@domain.tld>",
recipient=["you@domain.tld"])

# Initializing logger
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
logger.propagate = False
# Sending SimplemailLogger the Simplemail object, application name
# and the treshold
sl = SimplemailLogger(mail, __name__, logging.WARNING)
logger.addHandler(sl)

# Writing to the log
logger.warn("test")

The handler's constructor expects three arguments. One is mandatory: **mailobject** is the Simplemail object itself, which needs to be initialized before. Two others are optional: **app** contains your application name, which will be mentioned in the mail subject; and **level** which is the treshold at which the handler will be triggered.

## Downloads
This library is available at [PyPi](http://pypi.python.org/pypi/simplemail).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simplemail-0.3.tar.gz (4.1 kB view details)

Uploaded Source

File details

Details for the file simplemail-0.3.tar.gz.

File metadata

  • Download URL: simplemail-0.3.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for simplemail-0.3.tar.gz
Algorithm Hash digest
SHA256 3340f65d3ad0ef180f1062ee85456a5eb1522f524f0c5d495057f40a3d73465f
MD5 2888cc4cdf6181e4d5b9de506eefce3e
BLAKE2b-256 15be6aa54229ee6865bef431ed880bc806e7c0c580819205478150595c833184

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page