Skip to main content

Simple wrapper around `smtplib` and `email` libraries.

Project description

Postale

Postale is a simple module that wraps smtplib and email libraries. It is configured in order to make it easy to create a new mail, and setup attachments, body, etc.

Installation

pip install postale

Usage

Import it

You can either

import postale

or

from postale import Mail, Gmail

Mail is the most generic class in the module, Gmail inherits everything from it, but has specific arguments already set for the gmail client.

Note: The gmail SMTP provider needs you to set an App Password, different from your e-mail password.

Create an e-mail

To create a mail, use de Mail constructor:

my_mail = Mail(
    'smtp.host.com',
    port = 25,
    # other kwargs...
)

# With Gmail class you don't need to specify the host nor the port:
my_gmail = Mail(
    # kwargs...
)

You can specify all the e-mail properties, right in the constructor too:

my_mail = Mail(
    host = 'smtp.host.com',
    sender = 'email@example.com',
    subject = 'My First Mail',
    attachments = 'path/to/attachment.txt'
)

The following table shows the properties that class Mail has.

Property Type Optional Default In Gmail
host str No - No
port int Yes 587 No
sender str Yes None Yes
recipients str, list, tuple Yes None Yes
subject str Yes None Yes
body str Yes None Yes
attachments str, dict, bytes Yes None Yes

Printing

It is possible to convert a Mail object to str or simply print it. For example, printing my_mail defined above:

>>> print(my_mail)
        My First Mail
        From: email@example.com
        To:   

        (no body)

        attachment.txt

Edit an e-mail

You can create an e-mail and later edit its properties, by assigning them:

new_mail = Mail('smtp.host.com')
new_mail.recipients = ['friend@company.com', 'mom@server.com']
new_mail.subject = 'Things I like'
new_mail.body = "Chocolate, pizza and postales!"

Sending

It is necessary to have the sender's password to be able to send the e-mail. In order to do it, use the send method, it will return True when done.

new_mail.send('supersecurepass1234.')

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

postale-1.3.4.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

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

postale-1.3.4-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file postale-1.3.4.tar.gz.

File metadata

  • Download URL: postale-1.3.4.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.2

File hashes

Hashes for postale-1.3.4.tar.gz
Algorithm Hash digest
SHA256 b694ff1621f4f0250a939b43eed9bcc657b6cbf6f81a0ec6956d214da9078534
MD5 d5e0d6125e19a62732db1c53fc13695d
BLAKE2b-256 5298a1a1657f46515855fc4381137ffa6f429d406b1aef78ff63ceb88900d911

See more details on using hashes here.

File details

Details for the file postale-1.3.4-py3-none-any.whl.

File metadata

  • Download URL: postale-1.3.4-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.2

File hashes

Hashes for postale-1.3.4-py3-none-any.whl
Algorithm Hash digest
SHA256 1ee7d42064624267b0dd5d6a2459145ba9448881a369d2bd012e984a8a0359b2
MD5 dfc3cc35509f02a0a11ea017de41372c
BLAKE2b-256 a606e93f366b8f22ed9fd08b4a3c55b652f5a8d3c840432a8ccfb3d15e69a094

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