Reputation: 20147
I want to update my Email Host user and password, which is present in my database .. i don't know how to update it. but i mentioned it in my settings.py file. like this,
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'passxxpass'....
i want to change it dynamically while updating my database.
my table contain those email id and password. it may change dynamically based on user requirement. so i want do the same in EMAIL_HOST_USER
and PASSWORD
... to send my mail..
Upvotes: 1
Views: 1100
Reputation: 20147
I Solved this by importing the below package in my view file,
import django.conf as conf ...
and using this i made the changes whatever i want dynamically like, for changing my EMAIL_HOST by using like this,
get_mail_data = mymodels.objects.get(head='Admin')
conf.settings.EMAIL_HOST_USER = get_mail_data.from_mail
above is just an example what i used in my code... there from_mail is field present in my table.
Upvotes: 0
Reputation: 43300
Django's send_mail
(which I presume you're using) has two parameters for auth_user
and auth_password
, you should use these instead of trying to change settings
send_mass_mail
and others also have these parameters
Upvotes: 1
Reputation: 326
You cannot do this. Also, you should not do this.
A better way to do this by creating a "Variable" table in your database. Access the values from the table rather than settings file.
Upvotes: 0
Reputation: 599630
You should not do this. Settings are for things that don't change; if your email is dynamic, you should set that in the view when you send the mail.
Upvotes: 0