Dynamic Django Mail Configuration

后端 未结 4 1032
礼貌的吻别
礼貌的吻别 2020-12-17 21:20

I don\'t want to use email configuration fields in setting.py, i want to put them in to a model.

class Configuration(models.Model):
    email_use_tls = model         


        
4条回答
  •  死守一世寂寞
    2020-12-17 22:01

    There is little error in the answer above (Andrey Nelubin's answer). No need to call get_connection(backend=backend). You should pass backend to the EmailMessage constructor, like this:

    backend = EmailBackend(host=config.host, port=congig.port, username=config.username, 
                                   password=config.password, use_tls=config.use_tls, fail_silently=config.fail_silently)
    email = EmailMessage(subject='subj', body='body', from_email=from_email, to=to, 
                     connection=backend)
    

    I can not add comment that answer and dicided to post new one. Please someone who have permissions move it there or correct the answer.

提交回复
热议问题