Django: Test content of email sent
<p>I'm sending out an email to users with a generated link, and I wanna write a test that verifies whether the link is correct, but I can't find a way to get the content of the email inside the test.</p>

<p>Is there a way to do that?</p>

<p>If it helps at all, this is how I'm sending the email:</p>

<pre><code>content = template.render(Context({'my_link': my_link}))
subject = _('Email with link')
msg = EmailMultiAlternatives(subject=subject,
                             from_email='MyWebsite Team &lt;mywebsite@mywebsite.com&gt;',
                             to=[user.email, ])
msg.attach_alternative(content, 'text/html')
msg.send()
</code></pre>

<p>The docs have <a href="https://docs.djangoproject.com/en/1.10/topics/testing/tools/#email-services" rel="nofollow">an entire section</a> on testing emails.</p>

<pre><code>self.assertEqual(mail.outbox[0].subject, 'Email with link')
</code></pre>

python django django-testing