diff --git a/backend/accounts/utils.py b/backend/accounts/utils.py index ee02226..7ad390a 100644 --- a/backend/accounts/utils.py +++ b/backend/accounts/utils.py @@ -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( + """ +

Dear user,

+

To start generating your document, please confirm your email address by clicking the button below:

+

+ Confirm Email +

+

If you did not request this, you can safely ignore this message.

+

Best regards,
Risklet Team

+ """, + 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( + """ +

Dear customer,

+

Your document is almost ready. Please complete the payment process to unlock the final version.

+

+ + Proceed to Payment + +

+

If you have already completed the payment, you can ignore this message.

+

Best regards,
Risklet Team

+ """, + 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( + """ +

Hello,

+

A new document has been assigned to you for expert analysis. Please review the details below:

+

+ + View Document + + + Edit in Admin + +

+

Thank you for your contribution.

+

Best regards,
Risklet Team

+ """, + 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( + """ +

Hello,

+

We encountered an issue while generating the document. Please review and complete the document before sending it to the customer.

+

+ + View Document + + + Edit in Admin + +

+

Once you finish, save the document and share it with the customer.

+

Thank you for your help.
Risklet Team

+ """, + 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( - '

Your document is ready. Click the image below to view the full PDF:

' - '' - 'Document Preview', - document_link + content_html = format_html( + """ +

Your document is ready. Click the preview below to open the full PDF:

+

+ + Document Preview + +

+

If you have any questions, feel free to reach out.

+

Best regards,
Risklet Team

+ """, + 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', '') + image_attachment.add_header("Content-ID", "") 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( + """ +
+
+ Risklet Logo +

+ Risklet +

+
+
+

+ {} +

+
+ {} +
+
+ Risklet — Smart cybersecurity risk assessment +
+
+
+ """, + logo_url, + title, + content_html, + ) \ No newline at end of file