Thanks Doc. I did manage to find a solution. send_mail leverages smtplib, but only assumes user use LOGI AUTH after ehlo and STARTTLS. So I created a custom backend that uses PLAIN AUTH Method. I’ll leave the Code here if anybody needs it. Thanks.
from django.core.mail.backends.smtp import EmailBackend
import base64
class PlainAuthEmailBackend(EmailBackend):
def _send(self, email_message):
Override the _send method to use PLAIN authentication
if not self.connection:
self.open()
if not self.connection:
return False
# Encode credentials in PLAIN format
auth_string = f'\0{self.username}\0{self.password}'
auth_string_encoded = base64.b64encode(auth_string.encode('utf-8')).decode('utf-8')
print(f"Auth Creds: {auth_string_encoded}")
# Send AUTH PLAIN command
self.connection.docmd("AUTH PLAIN", auth_string_encoded)
# Send the email
return super()._send(email_message)
Thanks Doc. I did manage to find a solution. send_mail leverages smtplib, but only assumes user use LOGI AUTH after ehlo and STARTTLS. So I created a custom backend that uses PLAIN AUTH Method. I’ll leave the Code here if anybody needs it. Thanks.
from django.core.mail.backends.smtp import EmailBackend
import base64
class PlainAuthEmailBackend(EmailBackend):
def _send(self, email_message):
Override the _send method to use PLAIN authentication
if not self.connection:
self.open()
if not self.connection:
return False
# Encode credentials in PLAIN format
auth_string = f'\0{self.username}\0{self.password}'
auth_string_encoded = base64.b64encode(auth_string.encode('utf-8')).decode('utf-8')
print(f"Auth Creds: {auth_string_encoded}")
# Send AUTH PLAIN command
self.connection.docmd("AUTH PLAIN", auth_string_encoded)
# Send the email
return super()._send(email_message)