Skip to main content

Simple send mails as logging in Loguru

Project description

logmail

A simple package for sending emails (as simple, as writing logs with loguru)

Install

pip install logmail

or with poetry:

poetry add logmail

Usage

Setting global config:

from logmail import mailer

mailer.configure(
    smtp_host="mail.example.com",
    smtp_port=25,
    smtp_timeout=2,
    service_name="AWESOME SERVICE",
    recipient_list=["foo@example.com", "bar@example.com"],
    mail_from="Cool Mailer <noreply-some-service@example.com>",
)

From any *.py file in your awesome project:

from logmail import mailer

mailer.debug("This is debug message!")
mailer.info("This is info message!")
mailer.success("This is success message!")
mailer.warning("This is warning message!")
mailer.error("This is error message!")
mailer.critial("This is critial message!")

If you need to send email with custom params:

from logmail import mailer
...
mailer.send_mail(
    subject="Some subject", 
    message="Some message",  # may be html string
    mail_from="Mr Foo <foo@example.com>",
    recipient_list=["fizzbuzz@example.com"]
)

Advanced usage

You may see debugging info while sending emails by:

from logmail import mailer

...

with mailer.debugging():
    mailer.info("Mail sent with debugging this process")

You may easily set production and testing config by:

from logmail import mailer

mailer.configure(
    smtp_host="mail.example.com",
    smtp_port=25,
    smtp_timeout=2,
    service_name="AWESOME SERVICE",
    recipient_list=["foo@example.com", "bar@example.com"],
    mail_from="Cool Mailer <noreply-some-service@example.com>",
    testing=True,
    test_service_name="SOME TEST SERVICE",
    test_recipient_list=["testfoo@example.com", "testbar@example.com"],
    test_mail_from="Testing Cool Mailer <test-noreply-some-service@example.com>",
)

Setting global debugging while sending mails:

from logmail import mailer

# at configuration time
mailer.configure(
    ...
    debug=True
)

# in other place
mailer.set_debug(debug=True)

You may also set limit of exceptions in traceback (if it was raised):

from logmail import mailer

# at configuration time
mailer.configure(
    ...
    traceback_limit=666
)

# in other place
mailer.set_traceback_limit(666)

If you need to convert summary and message to html by default, try this:

from logmail import mailer

# at configuration time
mailer.configure(
    ...
    convert_all_data_to_html=True
)

# in other place
mailer.set_convert_all_data_to_html(True)

Note: logmail will apply convert_str_to_html method to summary and message with its default params every time when logmail sends not custom message

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

logmail-0.1.12.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

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

logmail-0.1.12-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file logmail-0.1.12.tar.gz.

File metadata

  • Download URL: logmail-0.1.12.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.5 CPython/3.8.5 Linux/5.8.0-50-generic

File hashes

Hashes for logmail-0.1.12.tar.gz
Algorithm Hash digest
SHA256 303e0046ca2dbf6c0c24163d957ad2a4c3ffcca023a9b733c6384a20b1286137
MD5 3172ea598053c69d317b4a98e484eb60
BLAKE2b-256 f2f2b44e7b23cea61890f26ca3692d7a07542197caaf32cf582f3b8c69663849

See more details on using hashes here.

File details

Details for the file logmail-0.1.12-py3-none-any.whl.

File metadata

  • Download URL: logmail-0.1.12-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.5 CPython/3.8.5 Linux/5.8.0-50-generic

File hashes

Hashes for logmail-0.1.12-py3-none-any.whl
Algorithm Hash digest
SHA256 a506a8889b344e34cfb20ea20317c670f044899ba70e2bc1d9285a0312f4ef73
MD5 58a203caaea48b9c2e5c4e6c93c8e2ec
BLAKE2b-256 b1e923da15028336250a7cff3b5b571e2121e5a4bd05460e8cb95ba41f141382

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