Open AlexLaroche opened 5 days ago
We could do it by writing an EmailSettings
model and providing a connection to the send_mail
function.
The User.mailing
method would essentially look like this:
+ from settings.models import EmailSettings
...
def mailing(self, email_template_name, subject, pk=False):
"""
Sending a mail to a user for password resetting or creation
"""
+ email_settings = EmailSettings.objects.get()
header = {
"email": self.email,
"root_url": CISO_ASSISTANT_URL,
"uid": urlsafe_base64_encode(force_bytes(self.pk)),
"user": self,
"token": default_token_generator.make_token(self),
"protocol": "https",
"pk": str(pk) if pk else None,
}
email = render_to_string(email_template_name, header)
try:
send_mail(
subject=subject,
message=email,
from_emailNone,
recipient_list[self.email],
fail_silently=False,
html_message=email,
+ connection=get_connection(host=email_settings.email_host, port=email_settings.email_port, ...)
)
logger.info("email sent", recipient=self.email, subject=subject)
...
https://docs.djangoproject.com/en/dev/topics/email/#obtaining-an-instance-of-an-email-backend https://docs.djangoproject.com/en/dev/topics/email/#send-mail
I'm quite confident it would work well, however we should think thoroughly about the potential blast radius of this change.
we will have to think about this one and how it will fit for the 1st init and how it would interact in SaaS enviornments