Skip to main content

Django app to store emails in db

Project description

Jemail

Django app to store emails in db

Installation

pip install jemail
pip install django-anymail[sendgrid]

Anymail used as email backend, for now jemail tested only with sendgrid backend.

Update settings with:

EMAIL_BACKEND = "anymail.backends.sendgrid.EmailBackend"

# defaults
JEMAIL = {
    "METADATA_ID_KEY": "message_id",  # tag name for EmailMessage.pk in message metadata
    "HTML_MESSAGE_UPLOAD_TO": "emails/messages/",  # path to save html messages to
    "ATTACHMENT_UPLOAD_TO": "emails/attachments/",  # path to save attachments to
    # "IMPORT_HTML_MESSAGE_UPLOAD_TO": "myproject.utils.message_upload_to",  # callable option
    # "IMPORT_ATTACHMENT_UPLOAD_TO": "myproject.utils.attachment_upload_to",  # callable option
}

Usage

from jemail import EmailMessage, EmailAttachment

# save email in db
EmailMessage.objects.create_with_objects(
    to=["user@example.com"],
    subject="Subject",
    # if body not provided it derived from html_message
    # using html2text library
    body="Hi User,...",
    html_message="<p>Hi User...",
    # the rest is optional
    from_email="no-reply@example.com",
    cc=["cc@example.com"],
    bcc=["bcc@example.com"],
    attachments=[
        EmailAttachment.objects.create(
            filename="doc.pdf",
            mimetype="application/pdf",
            file=ContentFile(b"...", name="doc.pdf"),
        )
    ],
    reply_to=["Example Team <support@example.com>"],
    created_by_id=user.pk,
)

# build EmailMultiAlternatives from db
msg = EmailMessage.objects.get(pk=pk).build_message()
# send email
msg.send()

Development

nix-direnv:

echo "use flake" >> .envrc
direnv allow
app.install
pytest

nix:

nix develop
app.install
pytest

uv:

uv -q venv .venv
source .venv/bin/activate
uv pip install -e .[dev,test]
pre-commit install
pytest

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

jemail-0.1a4.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

jemail-0.1a4-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file jemail-0.1a4.tar.gz.

File metadata

  • Download URL: jemail-0.1a4.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for jemail-0.1a4.tar.gz
Algorithm Hash digest
SHA256 04445821599a5e42649d4e3385b47c31af9389fdd02e34fa78f2bb8b270cb917
MD5 7d44e01f36aa39b992b949a55ffbc198
BLAKE2b-256 19dfb53fc8710ae64b21911d182f1c56cd757baefeff35cacc641b3528bfce82

See more details on using hashes here.

File details

Details for the file jemail-0.1a4-py3-none-any.whl.

File metadata

  • Download URL: jemail-0.1a4-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for jemail-0.1a4-py3-none-any.whl
Algorithm Hash digest
SHA256 2c05ed1d1e67ae0f67332806563ad17b7a490a9f75dfe0fc0ad5d6d4d1908396
MD5 420f2f88c42f7767984c40f140c52d0f
BLAKE2b-256 ca4e6cfc2cfb156e049e8920430d404e66b91a9b06bb2110cd948a5c4f6ed12c

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