Skip to main content

Handles sending emails using SMTP with complex attachments

Project description

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' }
)

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

email_smtp-1.0.3.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

email_smtp-1.0.3-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file email_smtp-1.0.3.tar.gz.

File metadata

  • Download URL: email_smtp-1.0.3.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.20

File hashes

Hashes for email_smtp-1.0.3.tar.gz
Algorithm Hash digest
SHA256 dd4200cfc0e96fe7462e13f2f8f5b350dac2451a21ff779f47fefb3242ec6446
MD5 ed74d05137f69c3a29491d43baad133f
BLAKE2b-256 3b070c4f39133c0d7ce88f2b858b7a5a3f0132a27efc1f11ba905e1ce488721c

See more details on using hashes here.

File details

Details for the file email_smtp-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: email_smtp-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.20

File hashes

Hashes for email_smtp-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b05dd6f82a514b49807b85b6447dc5f3f8abf96c94fcfd4e810394ba061bc5ec
MD5 671e485d929048a02d1ccc835b591acc
BLAKE2b-256 c69effad3b164914fbd9c3cc4798689a34e8d57969a40b98cb66b64f41bfb0fd

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