3

I'm trying to implement django-anymail with my site, and am having trouble.

Using these settings:

ANYMAIL = {
    "MAILGUN_API_KEY": "key-hahahahahahahahhaha... no",
}
EMAIL_BACKEND = "anymail.backends.mailgun.MailgunBackend"
DEFAULT_FROM_EMAIL = "account-recovery@mg.mycooldomain.com"

This works fine:

send_mail(
    "Test it!",
    "A new user [%s] has signed up" % (username),
    "Accounts <account-creation@mg.mycooldomain.com>",
    ["my_email@mycooldomain.com",]
)

The mail sends, it shows up in the mailgun logs, all is well.

But trying to use the in-built django registration password reset doesn't do anything.

The logs show no errors, all the templates are in the right place, it says the password reset worked but no emails show up in my inbox, nothing in the mailgun logs and not even anything in the spam box.

No emails show up at all. How can I make this work?


edit:

Also this works, but still no recovery:

from django.core.mail.message import EmailMessage
EmailMessage('hello','hello',recipients="my_email@gmail.com").send(False)
  • The difference between the `send_mail` call and the second one is that you are explicitly specifying a sender email. The password reset email uses `DEFAULT_FROM_EMAIL` - have you set this to something sensible in your settings? (the default is `webmaster@localhost` and Mailgun will probably reject that.) – solarissmoke Jul 08 '16 at 08:58
  • `DEFAULT_FROM_EMAIL` is set in `settings.py`, I just used an example as I didn't want to give out the real email. –  Jul 08 '16 at 09:33

1 Answers1

4

I figured out the answer, and it didn't come up elsewhere.

The call to send_mail worked as it forces an email to be sent.

However, password recovery has a lot of indirection, and one of the checks is if the user has_usable_password, which when you are working with dummy users during testing I forgot to do.

So, make sure your users have a password set before attempting to recover a password.