Hi folks,
any tips on testing email sending? Other than maybe creating a gmail account, especially for receiving those emails?
I would like to maybe store the emails locally, within a folder as they are sent.
Tips would be great! Thanks :)
Hi folks,
any tips on testing email sending? Other than maybe creating a gmail account, especially for receiving those emails?
I would like to maybe store the emails locally, within a folder as they are sent.
Tips would be great! Thanks :)
You can use a file backend for sending emails which is a very handy solution for development and testing; emails are not sent but stored in a folder you can specify!
Patching SMTPLib for testing purposes can help test sending mails without sending them.
For any project that doesn't require sending attachments, I use django-mailer, which has the benefit of all outbound emails ending up in a queue until I trigger their sending, and even after they've been sent, they are then logged - all of which is visible in the Admin, making it easy to quickly check what you emailing code is trying to fire off into the intertubes.
Django test framework has some built in helpers aid you with testing e-mail service.
Example from docs (short version):
from django.core import mail
from django.test import TestCase
class EmailTest(TestCase):
def test_send_email(self):
mail.send_mail('Subject here', 'Here is the message.',
'[email protected]', ['[email protected]'],
fail_silently=False)
self.assertEquals(len(mail.outbox), 1)
self.assertEquals(mail.outbox[0].subject, 'Subject here')