51 lines
1.6 KiB
Python
51 lines
1.6 KiB
Python
from django.core.mail import send_mail
|
|
from django.urls import reverse
|
|
from .models import EmailConfirmation
|
|
import uuid
|
|
from django.conf import settings
|
|
from django.utils.timezone import now
|
|
from backend.core.models import Document, Organization
|
|
|
|
|
|
|
|
def send_confirmation_email(email):
|
|
confirmation, created = EmailConfirmation.objects.get_or_create(email=email)
|
|
|
|
if not created:
|
|
confirmation.uuid = uuid.uuid4()
|
|
confirmation.created_at = now()
|
|
confirmation.save()
|
|
|
|
confirmation_link = f"http://127.0.0.1:8000{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.EMAIL_HOST_USER,
|
|
recipient_list=[email]
|
|
)
|
|
|
|
def send_payment_email(email):
|
|
organization = Organization.objects.get(email=email)
|
|
document = Document.objects.get(organization=organization)
|
|
|
|
payment_link = f"http://127.0.0.1:8000{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.EMAIL_HOST_USER,
|
|
recipient_list=[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,
|
|
)
|
|
|