10👍
There is no way to check that a mail has actually been received. This is not because of a failing in Django, but a consequence of the way email works.
If you need some form of definite delivery confirmation, you need to use something other than email.
9👍
When running unit tests emails are stored as EmailMessage objects in a list at django.core.mail.outbox
you can then perform any checks you want in your test class. Below is an example from django’s docs.
from django.core import mail
from django.test import TestCase
class EmailTest(TestCase):
def test_send_email(self):
# Send message.
mail.send_mail('Subject here', 'Here is the message.',
'from@example.com', ['to@example.com'],
fail_silently=False)
# Test that one message has been sent.
self.assertEqual(len(mail.outbox), 1)
# Verify that the subject of the first message is correct.
self.assertEqual(mail.outbox[0].subject, 'Subject here')
Alternatively if you just want to visually check the contents of the email during development you can set the EMAIL_BACKEND
to:
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
and then look at you console.
or
EMAIL_BACKEND = 'django.core.mail.backends.filebased.EmailBackend'
EMAIL_FILE_PATH = '/tmp/app-messages' # change this to a proper location
then check the file.
- [Django]-Syntax error whenever I put Python code inside a Django template
- [Django]-Django: related_name attribute (DatabaseError)
- [Django]-Convert python object to protocol buffer object
- [Django]-Is there a framework like now.js for Django?
- [Django]-Can Django REST Swagger be used to generate static HTML documentation?
3👍
- [Django]-Django extend admin "index" view
- [Django]-Creating a User Registration Page using MongoEngine
- [Django]-How do I get access to the request object when validating a django.contrib.comments form?
- [Django]-How to authenticate users with HttpOnly Cookie Django-React
- [Django]-Django-jquery-file-upload with model OneToOneField
2👍
In case of error, send_mail should raise an exception. The fail_silently argument makes possible to ignore the error. Did you enable this option by mistake?
I hope it helps
- [Django]-How to mark string for translation in jinja2 using trans blocks
- [Django]-Import parent module from submodule
- [Django]-Django: how to map the results of a raw sql query to model instances in admin list view?
- [Django]-Django Admin Remove default save message
- [Django]-Celery scheduled tasks with expiration time for each task instance?