Skip to main content

Email SMTP

Handles sending emails using SMTP

Install

pip install email_smtp

Requires

email_smtp requires python 3.10 or higher

Contents

Configuration

This library requires the use of config_oc to provide SMTP information and default email addresses.

Key Type Optional Description
email.error_to string | string[] yes The to address(es) to use if one is not passed to em.error().
email.from string yes The from address to use if one is not provided to em.send() or em.error().
email.smtp object yes The values required to setup a valid SMTP connection.
email.smtp.host string yes The hostname of the SMTP server, defaults to "localhost".
email.smtp.port integer yes The port of the SMTP server, defaults to 25.
email.smtp.tls boolean yes Set to true to require TLS when connecting to the server.
email.smtp.user string yes Must be set if the SMTP server requires a login.
email.smtp.passwd string yes Must be set if the SMTP server requires a login.

Example configuration

{
  "email": {
    "error_to": "errors@mydomain.com",
    "from": "noreply@mydomain.com",
    "smtp": {
      "host": "smtp.mydomain.com",
      "port": 587,
      "tls": true,
      "user": "smtpadmin@mydomain.com",
      "passwd": "password1234"
    }
  }
}

Send

from em import send, valid

def send_email(to, subject, text, html):

	if valid(to):
		send(to, subject, {
			'text': text,
			'html': html
		})

Send Parameters

Name Type Description
to str | str[] One or more email addresses to send the email to.
subject str The subject line of the email.
opts dict The parts of the email, like attachments and HTML content.
opts.attachments str[] | {'body': str, 'filename'}[] A list of attachments to add to the email
opts.bcc str | str[] One or more e-mail addresses to send a blind carbon copy to
opts.cc str | str[] One or more e-mail addresses to send a carbo copy to
opts.from str The e-mail address to show as having sent the e-mail
opts.html str The HTML version of the e-mail to send, this or text must be set
opts.reply-to str The e-mail address to mark as receiving any replies
opts.text str The text version of the e-mail to send, this or html must be set
opts.unsubscribe str The URL to add to the header for the receiver to be able to unsubscribe

Error

error is simply a shortcut for using config.email.error_to with a simple text message

import config
import em
import platform

# Calling error()
em.error('Error content')

# Is functionally equivalent to calling send()
#  with the following parameters
em.send(
	config.email.error_to(),
	'%s Error' % platform.node(),
	{ 'text': 'Error content' }
)

Metadata

Release files for email-smtp 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for email-smtp 1.0.3
File Size Uploaded Provenance
email_smtp-1.0.3.tar.gz 7.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for email-smtp 1.0.3
File Interpreter ABI Platform
email_smtp-1.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 13.4 kB

Release files / email_smtp-1.0.3.tar.gz

Download URL email_smtp-1.0.3.tar.gz
Size 7.0 kB
Tags Source
SHA-256 checksum
How to use checksums
dd4200cfc0e96fe7462e13f2f8f5b350dac2451a21ff779f47fefb3242ec6446
BLAKE2b-256 checksum
How to use checksums
3b070c4f39133c0d7ce88f2b858b7a5a3f0132a27efc1f11ba905e1ce488721c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.20

Release files / email_smtp-1.0.3-py3-none-any.whl

Download URL email_smtp-1.0.3-py3-none-any.whl
Size 6.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b05dd6f82a514b49807b85b6447dc5f3f8abf96c94fcfd4e810394ba061bc5ec
BLAKE2b-256 checksum
How to use checksums
c69effad3b164914fbd9c3cc4798689a34e8d57969a40b98cb66b64f41bfb0fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.20

Security for email-smtp 1.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page