Use DEFAULT_FROM_EMAIL instead of EMAIL_HOST_USER for the from email address if EMAIL_HOST_USER does not have an "@" sign in it.

Some email relay services require a username that is not an email address for the EMAIL_HOST_USER (e.g.: https://sendgrid.com/docs/API_Reference/SMTP_API/integrating_with_the_smtp_api.html)
This commit is contained in:
nswain
2020-08-26 10:39:01 -06:00
parent b5b308a757
commit d48e464c16

View File

@@ -2,7 +2,10 @@ from django.conf import settings
from django.core.mail import EmailMessage from django.core.mail import EmailMessage
def send(to,subject,body): def send(to,subject,body):
From = "%s <%s>" % (settings.EMAIL_FROM, settings.EMAIL_HOST_USER) from_email_address = settings.EMAIL_HOST_USER
if '@' not in from_email_address:
from_email_address = settings.DEFAULT_FROM_EMAIL
From = "%s <%s>" % (settings.EMAIL_FROM, from_email_address)
email = EmailMessage(subject,body,From,to) email = EmailMessage(subject,body,From,to)
email.content_subtype = "html" email.content_subtype = "html"
return email.send(False) return email.send(False)