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])}"
send_mail(
subject="Confirm your e-mail address",
message=f"Please click on the link to confirm your e-mail address: {confirmation_link}",
from_email=settings.DEFAULT_FROM_EMAIL,
recipient_list=[email]
content_html = format_html(
"""
<p>Dear user,</p>
<p>To start generating your document, please confirm your email address by clicking the button below:</p>
<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):
organization = Organization.objects.get(email=email)
document = Document.objects.get(organization=organization)
payment_link = f"{site_domain}{reverse('core:payment_page')}?email={email}"
send_mail(
subject="Complete your payment",
message=f"Click the link to proceed with payment: {payment_link}",
from_email=settings.DEFAULT_FROM_EMAIL,
recipient_list=[email],
fail_silently=False,
content_html = format_html(
"""
<p>Dear customer,</p>
<p>Your document is almost ready. Please complete the payment process to unlock the final version.</p>
<p style="text-align:center;margin:32px 0;">
<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):
subject = "Document for Expert Analysis"
document_link = f"{site_domain}{reverse('core:document', args=[document.id])}"
edit_link = f"{site_domain}{reverse('admin:core_document_change', args=[document.id])}"
message = f"""
You have been assigned a document for expert analysis.
Document ID: {document.id}
Document Link: {document_link}
Edit Document: {edit_link}
"""
send_mail(
subject=subject,
message=message,
from_email=settings.DEFAULT_FROM_EMAIL,
recipient_list=[email],
fail_silently=False,
content_html = format_html(
"""
<p>Hello,</p>
<p>A new document has been assigned to you for expert analysis. Please review the details below:</p>
<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;">
View Document
</a>
<a href="{}" style="display:inline-block;margin:0 8px;background:#28a745;color:#fff;
padding:12px 28px;border-radius:6px;text-decoration:none;font-weight:600;">
Edit in Admin
</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):
subject = "Incomplete Document Review Needed"
document_link = f"{site_domain}{reverse('core:document', args=[document.id])}"
edit_link = f"{site_domain}{reverse('admin:core_document_change', args=[document.id])}"
message = f"""
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.
Document ID: {document.id}
Document Link: {document_link}
Edit Document: {edit_link}
"""
send_mail(
subject=subject,
message=message,
from_email=settings.DEFAULT_FROM_EMAIL,
recipient_list=[email],
fail_silently=False,
content_html = format_html(
"""
<p>Hello,</p>
<p>We encountered an issue while generating the document. Please review and complete the document before sending it to the customer.</p>
<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;">
View Document
</a>
<a href="{}" style="display:inline-block;margin:0 8px;background:#28a745;color:#fff;
padding:12px 28px;border-radius:6px;text-decoration:none;font-weight:600;">
Edit in Admin
</a>
</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):
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
content_html = format_html(
"""
<p>Your document is ready. Click the preview below to open the full PDF:</p>
<p style="text-align:center;margin:32px 0;">
<a href="{}" target="_blank" style="display:inline-block;">
<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.attach_alternative(html_content, "text/html")
msg = EmailMultiAlternatives(
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.add_header('Content-ID', '<first_page>')
image_attachment.add_header("Content-ID", "<first_page>")
msg.attach(image_attachment)
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,
)