title: How to set SMTP for customer in production?
body: <p>What is the best practice for setting customer's SMTP in Django?</p>
  
  <p>Can I make them to set itself? I can't do that inside settings, otherwise they would have to tell me their password.</p>
  
  <pre><code>EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
  EMAIL_USE_TLS = True
  EMAIL_HOST = 'smtp.gmail.com'
  EMAIL_PORT = 587
  EMAIL_HOST_USER = '****@gmail.com'
  EMAIL_HOST_PASSWORD = '*****'
  </code></pre>
  
  <p>Is there a way? Maybe allow them to set credentials through Django admin?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>For now, the best way looks like to create a singleton object, let's call it <code>config</code>, to store credentials and register it in admin page to allow admins to set their credentials. Then, create one class for sending messages and do something like that:</p>
  
  <pre><code>backend = EmailBackend(host=config.host, port=config.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)
  </code></pre>
  
  <p>like here
  <a href="https://stackoverflow.com/a/22287776/3371056">https://stackoverflow.com/a/22287776/3371056</a></p>
  
  <p>But maybe there is some pattern to do such thing differently.</p>