def test_sends_multipart_email_with_attachments(self): send_templated_email( template_name='templated_email/test_fixture', context={'foo': 'bar'}, to=['*****@*****.**'], subject='Testing templated email', attachments=[('test.txt', 'file contents', 'text/plain')] ) self.assertEqual(len(mail.outbox), 1) # sanity check message = mail.outbox[0] with self.subTest('to'): self.assertEqual(message.to, ['*****@*****.**']) with self.subTest('subject'): self.assertEqual(message.subject, 'Testing templated email') with self.subTest('attachments'): self.assertEqual(message.attachments, [('test.txt', 'file contents', 'text/plain')]) with self.subTest('plain text body'): self.assertEqual(message.body, "Hi, foo was 'bar'.\n") self.assertEqual(message.content_subtype, 'plain') with self.subTest('html body'): self.assertEqual(len(message.alternatives), 1) # sanity check html_body, html_subtype = message.alternatives[0] self.assertEqual(html_body, "<p>Hi, foo was <strong>bar</strong>.</p>\n") self.assertEqual(html_subtype, 'text/html')
def send_to(self, email): subject = "Work you could do" send_templated_email( "sectors/email", {"report": self}, to=[email], subject=subject )
def send_report(report, email): subject = "Your travel time map report for {}".format(report.postcode) logger.debug("Sending report {} to {}".format(report.id, email)) send_templated_email( template_name="travel_report/emails/travel_report", context={"report": report}, to=[email], subject=subject, attachments=[ ("travel-report-{}.pdf".format(report.postcode), report.to_pdf(), "application/pdf"), ], )
def send_report(report, email): subject = "What sort of jobs you could do" logger.debug("Sending report {} to {}".format(report.id, email)) send_templated_email( template_name="sectors/emails/sectors_report", context={"report": report}, to=[email], subject=subject, attachments=[ ("sectors-report.pdf", report.to_pdf(), "application/pdf"), ], )
def send_job_discovery(report, email): logger.debug("Sending job discovery report to {}".format(email)) send_templated_email( template_name="job_discovery/emails/job_discovery_report", context={"report": report}, to=[email], subject="Your job discovery report", attachments=[ ("job-discovery-report.pdf", pdf.render(report), "application/pdf"), ], )
def send_quick_history(history, email): logger.debug("Sending quick history report to {}".format(email)) send_templated_email( template_name="quick_history/emails/quick_history_report", context={"report": history}, to=[email], subject="Your history snapshot", attachments=[ ("history-snapshot.pdf", pdf.render(history), "application/pdf"), ], )
def send_detailed_history(history, email): logger.debug("Sending detailed history report to {}".format(email)) send_templated_email( template_name="detailed_history/emails/detailed_history_report", context={"summary": history}, to=[email], subject="Your detailed history report", attachments=[ ("history-report.pdf", pdf.render(history), "application/pdf"), ], )
def send_feedback(name, email, content, tool, feedback_type, referring_url): subject = "Feedback: {} - {} - {}".format( tool, feedback_type, referring_url ) send_templated_email( template_name="home_page/emails/feedback", context={ "content": content, "from": { "name": name, "email": email } }, to=["*****@*****.**"], subject=subject )