smtp - django alternative EMAIL_HOST settings -
i want implement django managment command send emails smtp not default settings settings.py file such as:
email_host email_host_user email_host_password from_mail email_use_tls
i want send alternative settings different settings.py without change email settings site.
how implement this?
define alternate email settings , create new mail connection using settings:
settings.py
alternate_email_host_password = 'your password' alternate_email_host_user = 'your user' alternate_email_host = '' alternate_email_port = 123 alternate_email_use_tls = true
then create new connection using settings:
from django.core import mail django.core.mail import send_mail django.conf import settings # create new connection connection = mail.get_connection() connection.password = settings.alternate_email_host_password connection.username = settings.alternate_email_host_user connection.host = settings.alternate_email_host connection.port = settings.alternate_email_port connection.use_tls = settings.alternate_email_use_tls # send email using new connection created send_mail('my subject', 'my message', settings.default_from_email, ['abc@gmail.com'], connection=connection)
Comments
Post a Comment