Very interesting question. It looks like this is already implemented in the EmailMessage class.
First you need to set up an email backend
from django.core.mail import EmailMessage from django.core.mail.backends.smtp import EmailBackend config = Configuration.objects.get(**lookup_kwargs) backend = EmailBackend(host=config.host, port=congig.port, username=config.username, password=config.password, use_tls=config.use_tls, fail_silently=config.fail_silently)
Then just pass the connection to EmailMessage
email = EmailMessage(subject='subj', body='body', from_email=from_email, to=to, connection=backend)
Then send an email :)
email.send()
Ofc if you want html or attachment files to use EmailMultiAlternatives instead
source share