0
votes

I was configured email SMTP configurations in settings.py file as below

  • EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
  • EMAIL_USE_TLS = True
  • EMAIL_HOST = 'smtp.gmail.com'
  • EMAIL_HOST_USER = 'from mail'
  • EMAIL_HOST_PASSWORD = 'password'
  • EMAIL_PORT = 587

Now its working fine but my problem is after deploying the project how can I change any parameter like from_mail/password by user input form...Simply I need to update/change email or password.

2
in settings.py you need to import credential from different file(like yml file ) so no-one can see credential. and add yml file in .gitignore so i not going to upload into repository. and if you want to take email and password from user, you just need to send_mail function to do that. settings.py's credential not require there.Devang Hingu

2 Answers

0
votes

You can always change the parameter at the function call of the django email function:

send_mail(
 'Subject here',
 'Here is the message.',
 '[email protected]',
 ['[email protected]'],
 fail_silently=False,
)

How to set the auth_user/auth_password is explained here: Django Docs Sending email

0
votes

First, the Django documentation specifically says you shouldn't alter settings at runtime.

https://docs.djangoproject.com/en/2.2/topics/settings/#altering-settings-at-runtime

Fortunately, the send_mail() method allows the default EMAIL_* settings to overridden by using the auth_user and auth_password arguments.

send_mail(
 'Subject here',
 'Here is the message.',
 '[email protected]',
 ['[email protected]'],
 fail_silently=False,
 auth_user='new_user',
 auth_password='new_password',
)

Documentation: https://docs.djangoproject.com/en/2.2/topics/email/#send-mail