Got my answer here - https://stackoverflow.com/questions/43857594/django-set-e-mail-settings-in-view/43881974#43881974 Setting up values for connection object from database for specific reseller. Thanks
On Thu, Sep 23, 2021 at 11:09 AM Sujata Aghor <sujatas4ag...@gmail.com> wrote: > *settings.py : * > DEFAULT_FROM_EMAIL = '*****************' > EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' > EMAIL_HOST = 'smtp.gmail.com' > EMAIL_USE_TLS = True > EMAIL_PORT = *** > EMAIL_HOST_USER = '*********************" > EMAIL_HOST_PASSWORD = '***********" > > > *script.py :* > > from_email = DEFAULT_FROM_EMAIL > vars_dict = dict(tasks=usr_tasks, > reminder=reminder, > reseller=reseller, > logo=logo, > host=host, > ) > > # get values: r_email and r_pass specific to this reseller > r_obj = Reseller.objects.get(id=rid) > r_email = r_obj.remail if r_obj.remail else None > r_pass = r_obj.rpass if r_obj.rpass else None > > html_message = loader.render_to_string( > template,vars_dict) > > if subject and message and from_email: > print("Sending mail to %s"%recipient) > try: > if r_email and r_pass: > > send_mail(subject,message,from_email,recipient,fail_silently=True, > EMAIL_HOST_USER=r_email, > EMAIL_HOST_PASSWORD=r_pass, html_message=html_message) > else: > > send_mail(subject,message,from_email,recipient,fail_silently=True,html_message=html_message) > except Exception as e: > print(e) > else: > print("Mail sent successfully!") > > > --------------------------------------------------------------------------------------------------------------------------------- > Roughly this is my code. > in line - > send_mail(subject,message,from_email,recipient,fail_silently=True, > EMAIL_HOST_USER=r_email, > EMAIL_HOST_PASSWORD=r_pass, html_message=html_message) > its giving me error - send_mail() got an unexpected keyword argument > 'EMAIL_HOST_USER' > > Can you suggest anything about this ? > Thanks > > > On Thu, Sep 23, 2021 at 10:57 AM sum abiut <suab...@gmail.com> wrote: > >> If you don't mind sharing your code here. >> >> cheers, >> >> On Thu, Sep 23, 2021 at 4:17 PM Sujata Aghor <sujatas4ag...@gmail.com> >> wrote: >> >>> Hello Everyone, >>> I want to use different values of - EMAIL_HOST_USER & >>> EMAIL_HOST_PASSWORD for each of my users. I will take those values from >>> database and not from settings.py >>> >>> In django documentation I can see only a single paragraph about defining >>> a custom email backend, which is not giving me enough ideas. >>> >>> If I Try to change value of EMAIL_HOST_USER in script, it gives me below >>> error - >>> send_mail() got an unexpected keyword argument 'EMAIL_HOST_USER' >>> How to change these two values in a script? >>> Can anyone help here please. >>> >>> >>> -- >>> >>> Thanks & Regards! >>> Sujata S. Aghor >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Django users" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to django-users+unsubscr...@googlegroups.com. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/django-users/CAJCP8KC9Acj36VhnY1UqnpFtVb_xGLkZgmZJgPyugdhmH2QvOQ%40mail.gmail.com >>> <https://groups.google.com/d/msgid/django-users/CAJCP8KC9Acj36VhnY1UqnpFtVb_xGLkZgmZJgPyugdhmH2QvOQ%40mail.gmail.com?utm_medium=email&utm_source=footer> >>> . >>> >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Django users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to django-users+unsubscr...@googlegroups.com. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-users/CAPCf-y7FU4Emm28oKcZD09gwA78kzPAzN56XbynNHMrUDBAvMA%40mail.gmail.com >> <https://groups.google.com/d/msgid/django-users/CAPCf-y7FU4Emm28oKcZD09gwA78kzPAzN56XbynNHMrUDBAvMA%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> > > > -- > > Thanks & Regards! > Sujata S. Aghor > > -- Thanks & Regards! Sujata S. Aghor -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAJCP8KA3LQ_A8RkPZGiqkSaTmR1KBU%3Dg%2BNPhNFPGbfSrSLxw7g%40mail.gmail.com.