-
Notifications
You must be signed in to change notification settings - Fork 9
Use Django's Email Functionality #220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This doesn't work yet, as it depends on Django's builtin email stuff. That'll come next
Codecov Report
@@ Coverage Diff @@
## master #220 +/- ##
=======================================
Coverage 94.38% 94.38%
=======================================
Files 107 107
Lines 4699 4721 +22
Branches 270 270
=======================================
+ Hits 4435 4456 +21
- Misses 221 222 +1
Partials 43 43
Continue to review full report at Codecov.
|
Currently just ses, mailgun, and sendgrid. We can add more easily.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't make a new app for this, it will just lead to merge conflicts when we move it into core
in app restructure. IMO the best place for now is in the admin
app
Moving it into |
Now we assume email is disabled if `EMAIL_PROVIDER` is unset, and send emails to `django.core.mail.backends.dummy.EmailBackend` instead.
e2edffc
to
30eb4fe
Compare
I'm going to have another look at this once I'm awake and try and port the email templates to Django (which will also mean we can inline images), but this is more or less done. |
Have you considered #12 |
I'm fairly certain codecov is wrong here. |
How was this in the code base before...
What on earth is this core/src/authentication/views.py Lines 203 to 207 in 5ab5e9f
|
Feels like we should alert the user somehow if they've not set this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
"BACKEND": "django.template.backends.jinja2.Jinja2", # TODO: This is terrible | ||
"DIRS": [os.path.join(BASE_DIR, "templates")], | ||
"APP_DIRS": True, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be great if we could remove this in a subsequent PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Hi @thebeanogamer, can you check the code coverage error? |
Remaining work here:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You really knocked it out of the park this time. Just like you did last time,
and the time before that. Knowing you and that drive of yours, we’ll be
celebrating you again next week! Congratulations on this achievement. I already
know it will be one of many.
I am not sure how, but you did. Actually, now that I think about it, how did
you do it? Maybe one day you will share your secrets, and at least one person
will be able to compete with you (preferably me). Congratulations. You well
deserve it.
* Add Django Anymail * Don't just disable email, use Django's builtin * Add a page showing sent emails This doesn't work yet, as it depends on Django's builtin email stuff. That'll come next * Remove all our custom email code * Actually install the Mail app * Remove unused tests file * Remove now-needed code from staging.py * Remove dumb import catching * Remove unused imports * Just use getattr * Make sure we have anymail extras Currently just ses, mailgun, and sendgrid. We can add more easily. * Enable all the different AnyMail backends * Merge `mail` app into `admin` app * Swap to `EmailMultiAlternatives` * Remove some unused variables * Add SMTP settings * Replace references to settings.MAIL["SEND"] Now we assume email is disabled if `EMAIL_PROVIDER` is unset, and send emails to `django.core.mail.backends.dummy.EmailBackend` instead. * Fix AWS variable name * Revert change to Docker Compose * Remove random newline * Bring back the image in emails * Default mail provider in dev to console * Sendgrid is no longer a dependency * Swap email for loop to empty * Force email_enabled to false in testing * Issue users tokens even when mail is disabled How was this in the code base before... * Change default outbound email Feels like we should alert the user somehow if they've not set this * Don't break email verification * Catch SMTP errors or any errors from AnyMail * Fix email enabled syntax in tests
Currently we have a completely custom mail backend which was ripped from ractf/mail-usv and as a result barely works. This PR replaces that with Django's internal mail backend combined with Anymail. This means that instead of just supporting SMTP and SES (and Sendgrid, but it was never tested), we now support all of the following:
I've tested that SMTP and AWS work, as these are the ones we officially use and I'm reasonably confident that the others will work as that's abstracted away by Anymail. I've kept the existing environment variable names, so this should be backwards compatible.
Given that we can now inline images, I've also put the RACTF logo back into emails.
I've also added a dev mail page to
/api/v2/admin/list/
which is only enabled when theanymail.backends.test.EmailBackend
email backend is used, which will show the emails the platform has sent. This should make testing around emails easier.Resolves #217