def send_purchase_receipt(contrib_id, **kw): """ Sends an email to the purchaser of the app. """ contrib = Contribution.objects.get(pk=contrib_id) with contrib.user.activate_lang(): addon = contrib.addon version = addon.current_version or addon.latest_version # L10n: {0} is the app name. subject = _('Receipt for {0}').format(contrib.addon.name) data = { 'app_name': addon.name, 'developer_name': version.developer_name if version else '', 'price': contrib.get_amount_locale(get_locale_from_lang( contrib.source_locale)), 'date': datetime(contrib.created.date()), 'purchaser_email': contrib.user.email, #'purchaser_phone': '', # TODO: See bug 894614. #'purchaser_last_four': '', 'transaction_id': contrib.uuid, 'purchases_url': absolutify('/purchases'), 'support_url': addon.support_url, 'terms_of_service_url': absolutify(reverse('site.terms')), } log.info('Sending email about purchase: %s' % contrib_id) text_template = 'purchase/receipt.ltxt' html_template = 'purchase/receipt.html' send_html_mail_jinja(subject, html_template, text_template, data, recipient_list=[contrib.user.email])
def send_purchase_receipt(contrib_id, **kw): """ Sends an email to the purchaser of the app. """ contrib = Contribution.objects.get(pk=contrib_id) with contrib.user.activate_lang(): addon = contrib.addon version = addon.current_version or addon.latest_version # L10n: {0} is the app name. subject = _('Receipt for {0}').format(contrib.addon.name) data = { 'app_name': addon.name, 'developer_name': version.developer_name if version else '', 'price': contrib.get_amount_locale(get_locale_from_lang( contrib.source_locale)), 'date': datetime(contrib.created.date()), 'purchaser_email': contrib.user.email, #'purchaser_phone': '', # TODO: See bug 894614. #'purchaser_last_four': '', 'transaction_id': contrib.uuid, 'purchases_url': absolutify('/purchases'), 'support_url': addon.support_url, 'terms_of_service_url': absolutify('/terms-of-use'), } log.info('Sending email about purchase: %s' % contrib_id) text_template = 'purchase/receipt.ltxt' html_template = 'purchase/receipt.html' send_html_mail_jinja(subject, html_template, text_template, data, recipient_list=[contrib.user.email])
def test_send_html_mail_jinja(self): emails = ["*****@*****.**"] subject = u"Mozilla Add-ons: Thank you for your submission!" html_template = "devhub/email/submission.html" text_template = "devhub/email/submission.txt" send_html_mail_jinja( subject, html_template, text_template, context={}, recipient_list=emails, from_email=settings.NOBODY_EMAIL, use_blacklist=False, perm_setting="individual_contact", headers={"Reply-To": settings.EDITORS_EMAIL}, ) msg = mail.outbox[0] message = msg.message() eq_(msg.to, emails) eq_(msg.subject, subject) eq_(msg.from_email, settings.NOBODY_EMAIL) eq_(msg.extra_headers["Reply-To"], settings.EDITORS_EMAIL) eq_(message.is_multipart(), True) eq_(message.get_content_type(), "multipart/alternative") eq_(message.get_default_type(), "text/plain") payload = message.get_payload() eq_(payload[0].get_content_type(), "text/plain") eq_(payload[1].get_content_type(), "text/html") message1 = payload[0].as_string() message2 = payload[1].as_string() assert "<a href" not in message1, "text-only email contained HTML!" assert "<a href" in message2, "HTML email did not contain HTML!" unsubscribe_msg = unicode(users.notifications.individual_contact.label) assert unsubscribe_msg in message1 assert unsubscribe_msg in message2
def test_send_html_mail_jinja(self): emails = ['*****@*****.**'] subject = u'Mozilla Add-ons: Thank you for your submission!' html_template = 'devhub/email/submission.html' text_template = 'devhub/email/submission.txt' send_html_mail_jinja(subject, html_template, text_template, context={}, recipient_list=emails, from_email=settings.NOBODY_EMAIL, use_blacklist=False, perm_setting='individual_contact', headers={'Reply-To': settings.EDITORS_EMAIL}) msg = mail.outbox[0] message = msg.message() eq_(msg.to, emails) eq_(msg.subject, subject) eq_(msg.from_email, settings.NOBODY_EMAIL) eq_(msg.extra_headers['Reply-To'], settings.EDITORS_EMAIL) eq_(message.is_multipart(), True) eq_(message.get_content_type(), 'multipart/alternative') eq_(message.get_default_type(), 'text/plain') payload = message.get_payload() eq_(payload[0].get_content_type(), 'text/plain') eq_(payload[1].get_content_type(), 'text/html') message1 = payload[0].as_string() message2 = payload[1].as_string() assert '<a href' not in message1, 'text-only email contained HTML!' assert '<a href' in message2, 'HTML email did not contain HTML!' unsubscribe_msg = unicode(users.notifications.individual_contact.label) assert unsubscribe_msg in message1 assert unsubscribe_msg in message2
def send_welcome_email(addon_pk, emails, context, **kw): log.info(u'[1@None] Sending welcome email for %s to %s.' % (addon_pk, emails)) app = context.get('app', unicode(amo.FIREFOX.pretty)) subject = u'Mozilla Add-ons: Thanks for submitting a %s Add-on!' % app html_template = 'devhub/email/submission.html' text_template = 'devhub/email/submission.txt' return send_html_mail_jinja(subject, html_template, text_template, context, recipient_list=emails, from_email=settings.NOBODY_EMAIL, use_blacklist=False, perm_setting='individual_contact', headers={'Reply-To': settings.EDITORS_EMAIL})
def test_send_html_mail_jinja(self): emails = ['*****@*****.**'] subject = u'Test' html_template = 'tests/email/test.html' text_template = 'tests/email/test.txt' send_html_mail_jinja(subject, html_template, text_template, context={}, recipient_list=emails, from_email=settings.NOBODY_EMAIL, use_blacklist=False, perm_setting='individual_contact', headers={'Reply-To': settings.EDITORS_EMAIL}) msg = mail.outbox[0] message = msg.message() eq_(msg.to, emails) eq_(msg.subject, subject) eq_(msg.from_email, settings.NOBODY_EMAIL) eq_(msg.extra_headers['Reply-To'], settings.EDITORS_EMAIL) eq_(message.is_multipart(), True) eq_(message.get_content_type(), 'multipart/alternative') eq_(message.get_default_type(), 'text/plain') payload = message.get_payload() eq_(payload[0].get_content_type(), 'text/plain') eq_(payload[1].get_content_type(), 'text/html') message1 = payload[0].as_string() message2 = payload[1].as_string() assert '<a href' not in message1, 'text-only email contained HTML!' assert '<a href' in message2, 'HTML email did not contain HTML!' unsubscribe_msg = unicode(users.notifications.individual_contact.label) assert unsubscribe_msg in message1 assert unsubscribe_msg in message2