def _send_payment_received_email(invoice, locale): user = get_user_model().objects.get(stripe_customer_id=invoice.customer) subscription_info = retrieve_and_synchronize_subscription_info(user) locale = locale or settings.WIKI_DEFAULT_LANGUAGE context = { "payment_date": datetime.fromtimestamp(invoice.created), "next_payment_date": subscription_info["next_payment_at"], "invoice_number": invoice.number, "cost": invoice.total / 100, "credit_card_brand": subscription_info["brand"], "manage_subscription_url": absolutify(reverse("payment_management")), "faq_url": absolutify(reverse("payments_index")), "contact_email": settings.CONTRIBUTION_SUPPORT_EMAIL, } with translation.override(locale): subject = render_email("users/email/payment_received/subject.ltxt", context) # Email subject *must not* contain newlines subject = "".join(subject.splitlines()) plain = render_email("users/email/payment_received/plain.ltxt", context) send_mail_retrying( subject, plain, settings.DEFAULT_FROM_EMAIL, [user.email], attachment={ "name": os.path.basename(urlparse(invoice.invoice_pdf).path), "bytes": _download_from_url(invoice.invoice_pdf), "mime": "application/pdf", }, )
def payments_thank_you_email(username, user_email, recurring=False): """Create a notification email for new contributor.""" message_context = { 'user_email': user_email, 'username': username, 'support_mail_link': 'mailto:' + settings.CONTRIBUTION_SUPPORT_EMAIL + '?Subject=Recurring%20payment%20support', 'support_mail': settings.CONTRIBUTION_SUPPORT_EMAIL, 'recurring_payment': recurring, } # TODO: Remove when we ship translations, get legal approval locale = settings.WIKI_DEFAULT_LANGUAGE log.debug('Using the locale %s to send the contribution thank you email', locale) with translation.override(locale): subject = render_email('payments/email/thank_you/subject.ltxt', message_context) content_plain = render_email('payments/email/thank_you/plain.ltxt', message_context) content_html = render_email('payments/email/thank_you/email.html', message_context) email = EmailMultiAlternatives(subject, content_plain, settings.DEFAULT_FROM_EMAIL, [user_email]) email.attach_alternative(content_html, 'text/html') email.send()
def contribute_thank_you_email(username, user_email): """Create a notification email for new contributor.""" message_context = { 'user_email': user_email, 'username': username, } # TODO: Remove when we ship translations, get legal approval locale = settings.WIKI_DEFAULT_LANGUAGE log.debug('Using the locale %s to send the contribution thank you email', locale) with translation.override(locale): subject = render_email( 'contributions/email/thank_you/subject.ltxt', message_context ) content_plain = render_email( 'contributions/email/thank_you/plain.ltxt', message_context ) content_html = render_email( 'contributions/email/thank_you/email.html', message_context ) email = EmailMultiAlternatives( subject, content_plain, settings.DEFAULT_FROM_EMAIL, [user_email] ) email.attach_alternative(content_html, 'text/html') email.send()
def send_recovery_email(user_pk, email, locale=None): user = get_user_model().objects.get(pk=user_pk) locale = locale or settings.WIKI_DEFAULT_LANGUAGE url = settings.SITE_URL + user.get_recovery_url() context = {"recovery_url": url, "username": user.username} with translation.override(locale): subject = render_email("users/email/recovery/subject.ltxt", context) # Email subject *must not* contain newlines subject = "".join(subject.splitlines()) plain = render_email("users/email/recovery/plain.ltxt", context) send_mail(subject, plain, settings.DEFAULT_FROM_EMAIL, [email])
def send_recovery_email(user_pk, email, locale=None): user = get_user_model().objects.get(pk=user_pk) locale = locale or settings.WIKI_DEFAULT_LANGUAGE url = settings.SITE_URL + user.get_recovery_url() context = {'recovery_url': url, 'username': user.username} with translation.override(locale): subject = render_email('users/email/recovery/subject.ltxt', context) # Email subject *must not* contain newlines subject = ''.join(subject.splitlines()) plain = render_email('users/email/recovery/plain.ltxt', context) send_mail(subject, plain, settings.DEFAULT_FROM_EMAIL, [email])
def send_payment_received_email(stripe_customer_id, locale, timestamp, invoice_pdf): user = get_user_model().objects.get(stripe_customer_id=stripe_customer_id) locale = locale or settings.WIKI_DEFAULT_LANGUAGE context = { "payment_date": datetime.datetime.fromtimestamp(timestamp), "manage_subscription_url": absolutify(reverse("recurring_payment_management")), "faq_url": absolutify(reverse("payments_index")), "contact_email": settings.CONTRIBUTION_SUPPORT_EMAIL, "invoice_pdf": invoice_pdf, } with translation.override(locale): subject = render_email("users/email/payment_received/subject.ltxt", context) # Email subject *must not* contain newlines subject = "".join(subject.splitlines()) plain = render_email("users/email/payment_received/plain.ltxt", context) send_mail_retrying(subject, plain, settings.DEFAULT_FROM_EMAIL, [user.email])
def send_welcome_email(user_pk, locale): user = get_user_model().objects.get(pk=user_pk) if locale == settings.WIKI_DEFAULT_LANGUAGE or strings_are_translated( WELCOME_EMAIL_STRINGS, locale ): context = {"username": user.username} log.debug("Using the locale %s to send the welcome email", locale) with translation.override(locale): content_plain = render_email("users/email/welcome/plain.ltxt", context) content_html = render_email("users/email/welcome/html.ltxt", context) email = EmailMultiAlternatives( _("Getting started with your new MDN account"), content_plain, config.WELCOME_EMAIL_FROM, [user.email], ) email.attach_alternative(content_html, "text/html") email.send()
def send_welcome_email(user_pk, locale): user = get_user_model().objects.get(pk=user_pk) if (locale == settings.WIKI_DEFAULT_LANGUAGE or strings_are_translated(WELCOME_EMAIL_STRINGS, locale)): context = {'username': user.username} log.debug('Using the locale %s to send the welcome email', locale) with translation.override(locale): content_plain = render_email('users/email/welcome/plain.ltxt', context) content_html = render_email('users/email/welcome/html.ltxt', context) email = EmailMultiAlternatives( _('Take the next step to get involved on MDN!'), content_plain, config.WELCOME_EMAIL_FROM, [user.email], ) email.attach_alternative(content_html, 'text/html') email.send()
def payments_thank_you_email(username, user_email, recurring=False): """Create a notification email for new contributor.""" message_context = { 'user_email': user_email, 'username': username, 'support_mail_link': 'mailto:' + settings.CONTRIBUTION_SUPPORT_EMAIL + '?Subject=Recurring%20payment%20support', 'support_mail': settings.CONTRIBUTION_SUPPORT_EMAIL, 'recurring_payment': recurring, 'recurring_payment_management': absolutify(reverse('recurring_payment_management')), } # TODO: Remove when we ship translations, get legal approval locale = settings.WIKI_DEFAULT_LANGUAGE log.debug('Using the locale %s to send the contribution thank you email', locale) with translation.override(locale): subject = render_email( 'payments/email/thank_you/subject.ltxt', message_context ) content_plain = render_email( 'payments/email/thank_you/plain.ltxt', message_context ) content_html = render_email( 'payments/email/thank_you/email.html', message_context ) email = EmailMultiAlternatives( subject, content_plain, settings.DEFAULT_FROM_EMAIL, [user_email] ) email.attach_alternative(content_html, 'text/html') email.send()