Slanje dokumenta u PDF fajlu

This commit is contained in:
2025-02-24 10:19:27 +01:00
parent c9cf1cee86
commit 460f6a38a1
5 changed files with 64 additions and 25 deletions

View File

@@ -5,6 +5,11 @@ import uuid
from django.conf import settings
from django.utils.timezone import now
from backend.core.models import Document, Organization
from django.core.mail import EmailMultiAlternatives
from django.utils.html import format_html
from backend.core.utils import generate_first_page_image
from email.mime.image import MIMEImage
def send_confirmation_email(email):
confirmation, created = EmailConfirmation.objects.get_or_create(email=email)
@@ -37,12 +42,21 @@ def send_payment_email(email):
fail_silently=False,
)
def send_document_email(email, document_link):
send_mail(
subject="Your Document is Ready",
message=f"You can access your document at any time here: {document_link}",
from_email=settings.EMAIL_HOST_USER,
recipient_list=[email],
fail_silently=False,
def send_document_email(email, document_link, document):
image_io = generate_first_page_image(document)
subject = "Your Document is Ready"
html_content = format_html(
'<p>Your document is ready. Click the image below to view the full PDF:</p>'
'<a href="{}" target="_blank">'
'<img src="cid:first_page" style="width:100%;max-width:300px;" alt="Document Preview"/></a>',
document_link
)
msg = EmailMultiAlternatives(subject, "", "riskletdev@gmail.com", [email])
msg.attach_alternative(html_content, "text/html")
image_attachment = MIMEImage(image_io.getvalue(), "image/jpeg")
image_attachment.add_header('Content-ID', '<first_page>')
msg.attach(image_attachment)
msg.send()