I’m using django’s built-in auth system, and I’m using Sendgrid for my email backend. Users can create a new account and they get emailed a token for registration/authorization. However, I don’t seem to be getting emails when I user tries to reset a password. It’s possible that the user’s email server is blocking emails (I’ll look into that, but that could take days before I get response).
I looked at the django code and went to django/contrib/auth and then views.py and eventually found that password reset is sent with:
class PasswordResetForm(forms.Form):
email = forms.EmailField(
label=_("Email"),
max_length=254,
widget=forms.EmailInput(attrs={'autocomplete': 'email'})
)
def send_mail(self, subject_template_name, email_template_name,
context, from_email, to_email, html_email_template_name=None):
"""
Send a django.core.mail.EmailMultiAlternatives to `to_email`.
"""
subject = loader.render_to_string(subject_template_name, context)
# Email subject *must not* contain newlines
subject = ''.join(subject.splitlines())
body = loader.render_to_string(email_template_name, context)
email_message = EmailMultiAlternatives(subject, body, from_email, [to_email])
if html_email_template_name is not None:
html_email = loader.render_to_string(html_email_template_name, context)
email_message.attach_alternative(html_email, 'text/html')
email_message.send()
So I opened a django shell and tried this:
>>> from django.core.mail import EmailMultiAlternatives
>>> email_message = EmailMultiAlternatives(
... 'test subject 2',
... 'Here is the body.',
... 'doug@myemail.com',
... ['emailaddress@learn.vsb.bc.ca'],
... )
>>> email_message.send()
This mail was successfully sent and received at my intended email address. So it seems that the emails should be sent ok. Other than chasing down email blocking issues at learn.vsb.bc.ca
, is there anything else I should be looking at? Again, I’m using the stock django auth password reset functionality, I haven’t touched any of the code for this.