merge mail

This commit is contained in:
shamoon
2025-04-08 16:36:47 -07:00
parent 730636f38e
commit b7b343222c
3 changed files with 2 additions and 2 deletions

View File

@@ -1,38 +0,0 @@
from email import message_from_bytes
from pathlib import Path
from django.conf import settings
from django.core.mail import EmailMessage
from filelock import FileLock
def send_email(
subject: str,
body: str,
to: list[str],
attachment: Path | None = None,
attachment_mime_type: str | None = None,
) -> int:
"""
Send an email with an optional attachment.
TODO: re-evaluate this pending https://code.djangoproject.com/ticket/35581 / https://github.com/django/django/pull/18966
"""
email = EmailMessage(
subject=subject,
body=body,
to=to,
)
if attachment:
# Something could be renaming the file concurrently so it can't be attached
with FileLock(settings.MEDIA_LOCK), attachment.open("rb") as f:
content = f.read()
if attachment_mime_type == "message/rfc822":
# See https://forum.djangoproject.com/t/using-emailmessage-with-an-attached-email-file-crashes-due-to-non-ascii/37981
content = message_from_bytes(f.read())
email.attach(
filename=attachment.name,
content=content,
mimetype=attachment_mime_type,
)
return email.send()

View File

@@ -23,13 +23,13 @@ from django.utils import timezone
from filelock import FileLock
from guardian.shortcuts import remove_perm
from documents.mail import send_email
from documents.templating.workflows import parse_w_workflow_placeholders
from paperless import matching
from paperless.caching import clear_document_caches
from paperless.file_handling import create_source_path_directory
from paperless.file_handling import delete_empty_directories
from paperless.file_handling import generate_unique_filename
from paperless.mail import send_email
from paperless.models import Correspondent
from paperless.models import CustomField
from paperless.models import CustomFieldInstance