Package to dynamically construct and send HTML-based emails.
Project description
Introduction
emailconstructor is a simple tool for dynamically constructing and sending HTML-based emails. Some of it's high level features include:
- Composing email content using text and styled HTML elements.
- Adding email file attachments.
- Adding styled inline images.
- Creating HTML tables or lists from data sets with optional conditional styling applied per row or per data item.
emailconstructor was originally written for the specific use case of quickly building and sending conditional alert emails containing large amounts of tabular data, however it is suitable to be used in a wide variety of other applications.
Installation
pip install emailconstructor
Usage
All functionality is contained within the EmailConstructor class.
from emailconstructor import EmailConstructor
email = EmailConstructor(
smtp_server_url="smtpserver.domain.com",
smtp_server_port=100,
sender_address="senderemail@domain.com"
)
The subject, primary recipients, and CC recipients can all be set during initialization, or can be set/modified after.
email.subject = "Your subject"
email.primary_recipients.extend(["recipient1@domain.com", "recipient2@domain.com"])
email.cc_recipients.append("recipient3@domain.com")
Content can be added to the email using the add method while HTML elements are opened and closed using context manager classes.
email.add("This is some basic text followed by line breaks.")
email.line_break(count=3)
with email.span({"color": "red"}):
email.add("This text is inside the span tag and will appear red.")
with email.div({"font-size": "30px"}):
email.add("This text will appear in a large font ")
with email.span({"background-color": "yellow"}):
email.add("and this text will be highlighted.")
Tables and bullet lists can be easily created from data sets.
list_data = ["bullet 1", "bullet 2", "bullet 3"]
# Builds a simple <ul> bulleted list from the data
email.build_list(list_data)
table_data = [
OrderedDict({"column1": 1, "column2": 2}),
OrderedDict({"column1": 3, "column2": 4}),
OrderedDict({"column1": 5, "column2": 6}),
]
get_cell_style = lambda cell: {"color": "blue"} if cell % 2 == 0 else {}
# Builds a table with bolded headers and with even numbered cells colored blue
email.build_table(
table_data, header_style={"font-weight": "bold"}, get_cell_style=get_cell_style
)
Inline images and file attachments can be added by path.
email.add_inline_image("my_image.jpg", {"width": "100%"})
email.attachments.append("my_attachment.pdf")
Once finished, emails can be sent with the send method. A call to reset will clear out the email body, recipients, and subject so a new email can be built and sent.
email.send("emailpassword")
email.reset()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file emailconstructor-2.0.1.tar.gz.
File metadata
- Download URL: emailconstructor-2.0.1.tar.gz
- Upload date:
- Size: 12.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5dc978af4d59d796086149c39fec5a520c0e12020ac2d040bfe7f0f67b267505
|
|
| MD5 |
aa63e43ea2fdb9d5e9566a398eb9b168
|
|
| BLAKE2b-256 |
38d23b31b15b42c6684e0c5878e23bea09e2c695f920fac9166b581876cd5588
|
Provenance
The following attestation bundles were made for emailconstructor-2.0.1.tar.gz:
Publisher:
release.yml on ebier92/emailconstructor
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
emailconstructor-2.0.1.tar.gz -
Subject digest:
5dc978af4d59d796086149c39fec5a520c0e12020ac2d040bfe7f0f67b267505 - Sigstore transparency entry: 145859087
- Sigstore integration time:
-
Permalink:
ebier92/emailconstructor@0e7fde3d8ee927dd6c2902783632e14aa6843a65 -
Branch / Tag:
refs/heads/development - Owner: https://github.com/ebier92
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@0e7fde3d8ee927dd6c2902783632e14aa6843a65 -
Trigger Event:
workflow_run
-
Statement type:
File details
Details for the file emailconstructor-2.0.1-py3-none-any.whl.
File metadata
- Download URL: emailconstructor-2.0.1-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5503ec6fef903115e574af00eb6a00d41225f338842e9ea8a2d7009a543741df
|
|
| MD5 |
50d7dc222de597a5000a37527ecfa11d
|
|
| BLAKE2b-256 |
d1ff8078f807b8c040b55951202d73698f285feb26b35e3be03b2e73bd90c5db
|
Provenance
The following attestation bundles were made for emailconstructor-2.0.1-py3-none-any.whl:
Publisher:
release.yml on ebier92/emailconstructor
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
emailconstructor-2.0.1-py3-none-any.whl -
Subject digest:
5503ec6fef903115e574af00eb6a00d41225f338842e9ea8a2d7009a543741df - Sigstore transparency entry: 145859088
- Sigstore integration time:
-
Permalink:
ebier92/emailconstructor@0e7fde3d8ee927dd6c2902783632e14aa6843a65 -
Branch / Tag:
refs/heads/development - Owner: https://github.com/ebier92
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@0e7fde3d8ee927dd6c2902783632e14aa6843a65 -
Trigger Event:
workflow_run
-
Statement type: