Skip to main content

Send email with python, my way

Project description

Mercurio

Send email with python, my way.

Mercurio is a simple class to send email with python, managing smtp, attachments and mimetypes, multiple recipients, attachments with a specific content id (to html email templating)...

Installation

Installation is as easy as run: pip install mercurio

Usage

To initialize a mercurio instance simply call it with typical smtp parameters. No connection will be opened at this stage, then you can initialize and reuse it during the whole code.

from mercurio import mercurio

hg = mercurio(
    host="smtp.test.com",
    port=25,
    smtp_user="myuser",
    smtp_pwd="mypwd"
)

To debug purposes, you can create the message and save it in a file without send it thgrougth smtp. You can open such file with a normal email client.

message = hg.make_message(
    fromaddress="from@me.com",
    recipient="to@me.com",
    reply_to_address="reply@to.me",
    text="a long text, very long.",
    sbj="The subject, or the object?",
    attachments=[],
    cid_attachments={}
)

with open('test_email.eml', 'w') as o:
    o.write(message.as_string())

Send a real message is easy: use an hg instance, and call send method with its parameters. Note that you can send multiple type of attachments (images, xlsx, json, txt). Mercurio can choice the correct mime type. You can also use attachment with a specific content id, that can be used in html email to include images in the body of the message.

hg.send(
    fromaddress="from@me.com",
    recipients=["to@me.com"],
    reply_to_address="reply@to.me",
    text="a long text, very long.",
    sbj="The subject, or the object?",
    attachments=[],
    cid_attachments={"content_id_01": "mylogo.png"}
)

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

mercurio-0.10.2.tar.gz (5.4 kB view details)

Uploaded Source

File details

Details for the file mercurio-0.10.2.tar.gz.

File metadata

  • Download URL: mercurio-0.10.2.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for mercurio-0.10.2.tar.gz
Algorithm Hash digest
SHA256 d20bcfdbac3a130f4381d9742589cd5881bfbbc8040b2d8838de969c7e10c4dc
MD5 dcf60e71941ffd94797820aa7df88495
BLAKE2b-256 2fa84fa4da1a435ed58f6ab9e91e61596390bed039ae6c54be4c25a744eed1b0

See more details on using hashes here.

Supported by

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