Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.
/ ssl-smtp-handler Public archive

A standard library compatible logging handler which sends mail via SMTP_SSL

License

Notifications You must be signed in to change notification settings

dycw/ssl-smtp-handler

Repository files navigation

ssl-smtp-handler

PyPI version

Introduction

I wanted an easy way to send emails for my Python projects, with code that was adapted for today's (2021) way of doing things. This Handler is designed for use with the Python standard library.

Requirements

  • Python 3.6+ (the currently supported versions of Python)

Installation

pip install ssl-smtp-handler

Usage

Gmail is probably the easiest to set up. For example:

from logging import basicConfig, info
from ssl_smtp_handler import SSLSMTPHandler

handler = SSLSMTPHandler(
    mailhost='smtp.gmail.com',
    fromaddr='username@gmail.com',
    toaddrs=['to@gmail.com'],
    subject='Example subject',
    credentials=('username@gmail.com', 'password'),
)
handler.setLevel('INFO')
basicConfig(handlers=[handler], level='INFO')
info('This is an example message')

To try this for yourself, get hold a Gmail account and enable 2-Step verification:

screenshot1.png

Create an app password:

screenshot2.png

Name it whatever you want:

screenshot3.png

Use this password in your program:

screenshot4.png

About

A standard library compatible logging handler which sends mail via SMTP_SSL

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages