Added email template

This commit is contained in:
2025-10-08 18:04:10 +02:00
parent 82fbbb1c9f
commit 401898fc26

View File

@@ -22,83 +22,226 @@ def send_confirmation_email(email):
confirmation_link = f"{site_domain}{reverse('confirm_email', args=[confirmation.uuid])}" confirmation_link = f"{site_domain}{reverse('confirm_email', args=[confirmation.uuid])}"
send_mail( content_html = format_html(
subject="Confirm your e-mail address", """
message=f"Please click on the link to confirm your e-mail address: {confirmation_link}", <p>Dear user,</p>
from_email=settings.DEFAULT_FROM_EMAIL, <p>To start generating your document, please confirm your email address by clicking the button below:</p>
recipient_list=[email] <p style="text-align:center;margin:32px 0;">
<a href="{}" style="background:orange;color:#19161C;padding:12px 32px;
border-radius:6px;text-decoration:none;font-weight:600;">Confirm Email</a>
</p>
<p style="color:#929292;">If you did not request this, you can safely ignore this message.</p>
<p>Best regards,<br>Risklet Team</p>
""",
confirmation_link
) )
html_message = render_email_template(content_html, title="Confirm Your Email")
msg = EmailMultiAlternatives(
subject="Confirm your email to start document generation",
body=html_message,
from_email=settings.DEFAULT_FROM_EMAIL,
to=[email]
)
msg.content_subtype = "html"
msg.send()
def send_payment_email(email): def send_payment_email(email):
organization = Organization.objects.get(email=email)
document = Document.objects.get(organization=organization)
payment_link = f"{site_domain}{reverse('core:payment_page')}?email={email}" payment_link = f"{site_domain}{reverse('core:payment_page')}?email={email}"
send_mail( content_html = format_html(
subject="Complete your payment", """
message=f"Click the link to proceed with payment: {payment_link}", <p>Dear customer,</p>
from_email=settings.DEFAULT_FROM_EMAIL, <p>Your document is almost ready. Please complete the payment process to unlock the final version.</p>
recipient_list=[email], <p style="text-align:center;margin:32px 0;">
fail_silently=False, <a href="{}" style="background:#28a745;color:#fff;padding:12px 32px;
border-radius:6px;text-decoration:none;font-weight:600;display:inline-block;">
Proceed to Payment
</a>
</p>
<p style="color:#929292;">If you have already completed the payment, you can ignore this message.</p>
<p>Best regards,<br>Risklet Team</p>
""",
payment_link,
) )
html_message = render_email_template(content_html, title="Complete Your Payment")
msg = EmailMultiAlternatives(
subject="Complete your payment to finish document generation",
body=html_message,
from_email=settings.DEFAULT_FROM_EMAIL,
to=[email],
)
msg.content_subtype = "html"
msg.send()
def send_documet_to_expert(email, document): def send_documet_to_expert(email, document):
subject = "Document for Expert Analysis"
document_link = f"{site_domain}{reverse('core:document', args=[document.id])}" document_link = f"{site_domain}{reverse('core:document', args=[document.id])}"
edit_link = f"{site_domain}{reverse('admin:core_document_change', args=[document.id])}" edit_link = f"{site_domain}{reverse('admin:core_document_change', args=[document.id])}"
message = f""" content_html = format_html(
You have been assigned a document for expert analysis. """
Document ID: {document.id} <p>Hello,</p>
Document Link: {document_link} <p>A new document has been assigned to you for expert analysis. Please review the details below:</p>
Edit Document: {edit_link} <p style="text-align:center;margin:24px 0;">
""" <a href="{}" style="display:inline-block;margin:0 8px;background:#0E3B43;color:#fff;
padding:12px 28px;border-radius:6px;text-decoration:none;font-weight:600;">
send_mail( View Document
subject=subject, </a>
message=message, <a href="{}" style="display:inline-block;margin:0 8px;background:#28a745;color:#fff;
from_email=settings.DEFAULT_FROM_EMAIL, padding:12px 28px;border-radius:6px;text-decoration:none;font-weight:600;">
recipient_list=[email], Edit in Admin
fail_silently=False, </a>
</p>
<p>Thank you for your contribution.</p>
<p>Best regards,<br>Risklet Team</p>
""",
document_link,
edit_link,
) )
html_message = render_email_template(content_html, title="New Expert Assignment")
msg = EmailMultiAlternatives(
subject="Document assigned for expert analysis",
body=html_message,
from_email=settings.DEFAULT_FROM_EMAIL,
to=[email],
)
msg.content_subtype = "html"
msg.send()
def send_document_to_reviewer(email, document): def send_document_to_reviewer(email, document):
subject = "Incomplete Document Review Needed"
document_link = f"{site_domain}{reverse('core:document', args=[document.id])}" document_link = f"{site_domain}{reverse('core:document', args=[document.id])}"
edit_link = f"{site_domain}{reverse('admin:core_document_change', args=[document.id])}" edit_link = f"{site_domain}{reverse('admin:core_document_change', args=[document.id])}"
message = f""" content_html = format_html(
We had some problems generating document, please review and complete it as needed. """
When u are done, please save document, and send it to the customer. <p>Hello,</p>
Document ID: {document.id} <p>We encountered an issue while generating the document. Please review and complete the document before sending it to the customer.</p>
Document Link: {document_link} <p style="text-align:center;margin:24px 0;">
Edit Document: {edit_link} <a href="{}" style="display:inline-block;margin:0 8px;background:#0E3B43;color:#fff;
""" padding:12px 28px;border-radius:6px;text-decoration:none;font-weight:600;">
View Document
send_mail( </a>
subject=subject, <a href="{}" style="display:inline-block;margin:0 8px;background:#28a745;color:#fff;
message=message, padding:12px 28px;border-radius:6px;text-decoration:none;font-weight:600;">
from_email=settings.DEFAULT_FROM_EMAIL, Edit in Admin
recipient_list=[email], </a>
fail_silently=False, </p>
<p>Once you finish, save the document and share it with the customer.</p>
<p>Thank you for your help.<br>Risklet Team</p>
""",
document_link,
edit_link,
) )
html_message = render_email_template(content_html, title="Document Review Required")
msg = EmailMultiAlternatives(
subject="Document review required",
body=html_message,
from_email=settings.DEFAULT_FROM_EMAIL,
to=[email],
)
msg.content_subtype = "html"
msg.send()
def send_document_email(email, document_link, document): def send_document_email(email, document_link, document):
image_io = generate_first_page_image(document) image_io = generate_first_page_image(document)
subject = "Your Document is Ready" content_html = format_html(
html_content = format_html( """
'<p>Your document is ready. Click the image below to view the full PDF:</p>' <p>Your document is ready. Click the preview below to open the full PDF:</p>
'<a href="{}" target="_blank">' <p style="text-align:center;margin:32px 0;">
'<img src="cid:first_page" style="width:100%;max-width:300px;" alt="Document Preview"/></a>', <a href="{}" target="_blank" style="display:inline-block;">
document_link <img src="cid:first_page" style="width:100%;max-width:320px;border:1px solid #0E3B43;
border-radius:12px;" alt="Document Preview">
</a>
</p>
<p>If you have any questions, feel free to reach out.</p>
<p>Best regards,<br>Risklet Team</p>
""",
document_link,
) )
html_message = render_email_template(content_html, title="Your Document is Ready")
msg = EmailMultiAlternatives(subject, "", settings.DEFAULT_FROM_EMAIL, [email]) msg = EmailMultiAlternatives(
msg.attach_alternative(html_content, "text/html") subject="Your document is ready",
body=html_message,
from_email=settings.DEFAULT_FROM_EMAIL,
to=[email],
)
msg.content_subtype = "html"
image_attachment = MIMEImage(image_io.getvalue(), "image/jpeg") image_attachment = MIMEImage(image_io.getvalue(), "image/jpeg")
image_attachment.add_header('Content-ID', '<first_page>') image_attachment.add_header("Content-ID", "<first_page>")
msg.attach(image_attachment) msg.attach(image_attachment)
msg.send() msg.send()
def render_email_template(content_html, title = 'Risklet Notifications'):
logo_url = f"https://risklet.com/static/img/risklet-icon.png"
return format_html(
"""
<div style="
margin:32px auto;
background:#fff;
border:1px solid #0E3B43;
border-radius:16px;
font-family:'Darker Grotesque',Arial,sans-serif;
color:#0E3B43;
box-shadow:0 4px 24px rgba(14,59,67,0.07);
">
<div style="
background:#0E3B43;
margin:0;
padding:24px 0;
text-align:center;
border-top-left-radius:16px;
border-top-right-radius:16px;
">
<img src="{}" alt="Risklet Logo" style="
display:block;
margin:0 auto 12px auto;
height:56px;
width:auto;
border:none;
">
<h2 style="
margin:0;
color:#fff;
font-weight:800;
font-size:24px;
letter-spacing:1px;
">
Risklet
</h2>
</div>
<div style="padding:32px 24px;">
<h2 style="
color:#0E3B43;
text-align:center;
margin:0 0 24px 0;
font-weight:800;
letter-spacing:1px;
">
{}
</h2>
<div style="font-size:1.15em;line-height:1.7;">
{}
</div>
<div style="
margin-top:32px;
text-align:center;
color:#0E3B43;
font-size:1em;
font-weight:600;
">
Risklet &mdash; Smart cybersecurity risk assessment
</div>
</div>
</div>
""",
logo_url,
title,
content_html,
)