mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-29 11:09:27 -05:00
Fix: use MIMEBase for email attachments
This commit is contained in:
parent
283bcb4c91
commit
eb60f3917f
@ -1,6 +1,9 @@
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
from email.encoders import encode_base64
|
||||||
|
from email.mime.base import MIMEBase
|
||||||
|
from email.utils import encode_rfc2231
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
@ -979,9 +982,25 @@ def run_workflows(
|
|||||||
)
|
)
|
||||||
if action.email.include_document:
|
if action.email.include_document:
|
||||||
# Something could be renaming the file concurrently so it can't be attached
|
# Something could be renaming the file concurrently so it can't be attached
|
||||||
with FileLock(settings.MEDIA_LOCK):
|
with FileLock(settings.MEDIA_LOCK), open(original_file, "rb") as f:
|
||||||
document.refresh_from_db()
|
file_content = f.read()
|
||||||
email.attach_file(original_file)
|
|
||||||
|
main_type, sub_type = (
|
||||||
|
document.mime_type.split("/", 1)
|
||||||
|
if document.mime_type
|
||||||
|
else ("application", "octet-stream")
|
||||||
|
)
|
||||||
|
mime_part = MIMEBase(main_type, sub_type)
|
||||||
|
mime_part.set_payload(file_content)
|
||||||
|
|
||||||
|
encode_base64(mime_part)
|
||||||
|
|
||||||
|
mime_part.add_header(
|
||||||
|
"Content-Disposition",
|
||||||
|
f'attachment; filename="{encode_rfc2231(str(original_file.name))}"',
|
||||||
|
)
|
||||||
|
|
||||||
|
email.attach(mime_part)
|
||||||
n_messages = email.send()
|
n_messages = email.send()
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"Sent {n_messages} notification email(s) to {action.email.to}",
|
f"Sent {n_messages} notification email(s) to {action.email.to}",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user