Wednesday 9 December 2020

Adding a Dynamic Email Backend in Django

I would like to let my users decide their email backend on their own. That is why I have created the email relevant keys (host, port, username...) on the users and now I try to work this (see below) backend into my Django project. Working with the docs and the source code, my first attempt was to extend the default EmailBackend by my custom "UserBackend" which overrides the __init__ function like this:

class UserBackend(EmailBackend):
    def __init__(self, user_id, host=None, port=None, username=None ...):
        user = User.objects.get(id=user_id)
        super().init(host=user.email_host, port=user.email_port ...)

As this method is called (I tried to send_mail from the shell) it gets no user_id. How can I approach this differently or how would I extend my attempts to do this? I wouldn't want to rewrite Djangos mail system entirely, as it works in itself.



from Adding a Dynamic Email Backend in Django

No comments:

Post a Comment