def expires_soon_notice(sender, subscription, nb_days, **kwargs): broker = get_broker() broker_recipients, broker_bcc = _notified_recipients( broker, 'expires_soon') if subscription.organization.email: site = get_current_site() app = get_current_app() back_url = "%s?plan=%s" % (site.as_absolute_uri( reverse('saas_organization_cart', args=(subscription.organization, ))), subscription.plan) LOGGER.debug("[signal] expires_soon_notice("\ " subscription=%s, nb_days=%s)", subscription, nb_days) if SEND_EMAIL: recipients, bcc = _notified_recipients(subscription.organization, 'expires_soon') get_email_backend(connection=app.get_connection()).send( from_email=app.get_from_email(), recipients=recipients, reply_to=broker_recipients[0], bcc=bcc + broker_recipients + broker_bcc, template='notification/expires_soon.eml', context={ 'broker': get_broker(), 'app': app, 'back_url': back_url, 'nb_days': nb_days, 'organization': subscription.organization, 'plan': subscription.plan, 'provider': subscription.plan.organization }) else: LOGGER.warning( "%s will not be notified of soon expired subscription"\ " because e-mail address is invalid.", subscription.organization)
def on_question_new(sender, question, request, *args, **kwargs): broker = request.session.get('site', {}) notify_email = broker['email'] get_email_backend().send( recipients=[notify_email], template='notification/question_new.eml', context={'question': question, 'site': get_site(request)})
def weekly_sales_report_notice(sender, provider, dates, data, **kwargs): app = get_current_app() recipients, bcc = _notified_recipients(provider, "weekly_sales_report_created") if SEND_EMAIL: frm = app.get_from_email() # if from is empty the following command will fail if not frm: raise Exception( "Please fill the DEFAULT_FROM_EMAIL option in settings") prev_week, _ = dates last_sunday = prev_week[-1] date = last_sunday.strftime("%A %b %d, %Y") # XXX using the provider in templates is incorrect. "Any questions # or comments..." should show DjaoDjin support email address. get_email_backend(connection=app.get_connection()).send( from_email=frm, recipients=recipients, bcc=bcc, template='notification/weekly_sales_report_created.eml', context={ 'broker': get_broker(), 'provider': provider, # Without ``app`` we don't set the color correctly in # in notification/base.html, thus ending with an error # in premailer. 'app': app, 'table': data, 'date': date })
def user_activated_notice(sender, user, verification_key, request, **kwargs): """ A new user has activated his account. We have a complete profile and active email address now. """ broker = get_broker() site = get_current_site() recipients, bcc = _notified_recipients(broker, "user_activated_notice") app = get_current_app() LOGGER.debug( "[signal] user_activated_notice(user=%s, verification_key=%s)", user, verification_key) if SEND_EMAIL: get_email_backend(connection=app.get_connection()).send( from_email=app.get_from_email(), recipients=recipients, bcc=bcc, template='notification/user_activated.eml', context={ 'request': request, 'broker': get_broker(), 'app': app, 'user': get_user_context(user), 'urls': { 'user': { 'profile': site.as_absolute_uri( reverse('users_profile', args=(user, ))) } } })
def user_registered_notice(sender, user, **kwargs): """ A new user has registered (frictionless or completely) """ LOGGER.debug("[signal] user_registered_notice(user=%s)", user) if not SEND_EMAIL: return broker = get_broker() app = get_current_app() site = get_current_site() if settings.FEATURES_DEBUG: back_url = site.as_absolute_uri() get_email_backend(connection=site.get_email_connection()).send( from_email=site.get_from_email(), recipients=[user.email], template='notification/user_welcome.eml', context={ 'broker': get_broker(), 'app': app, 'user': get_user_context(user), 'back_url': back_url }) recipients, bcc = _notified_recipients(broker, "user_registered_notice") if recipients: get_email_backend(connection=site.get_email_connection()).send( from_email=site.get_from_email(), recipients=recipients, bcc=bcc, template='notification/user_registered.eml', context={ 'broker': get_broker(), 'app': app, 'user': get_user_context(user) })
def _send_notification_email(from_site, recipients, template, context=None, reply_to=None, bcc=None): """ Sends a notification e-mail using the current site connection, defaulting to sending an e-mail to broker profile managers if there is any problem with the connection settings. """ try: get_email_backend(connection=from_site.get_email_connection()).send( from_email=from_site.get_from_email(), recipients=recipients, reply_to=reply_to, bcc=bcc, template=template, context=context) except smtplib.SMTPException as err: LOGGER.warning( "[signal] problem sending email from %s on connection for %s. %s", from_site.get_from_email(), from_site, err) context.update({'errors': [_("There was an error sending"\ " the following email to %(recipients)s. This is most likely due to"\ " a misconfiguration of the e-mail notifications whitelabel settings"\ " for your site %(site)s.") % { 'recipients': recipients, 'site': from_site.as_absolute_uri()}]}) #pylint:disable=unused-variable notified_on_errors, notused = _notified_recipients( get_organization_model().objects.using(from_site._state.db).get( pk=from_site.account_id), "") if notified_on_errors: get_email_backend( connection=get_connection_base(fail_silently=True)).send( from_email=settings.DEFAULT_FROM_EMAIL, recipients=notified_on_errors, template=template, context=context)
def contact_requested_notice(sender, provider, user, reason, **kwargs): """ Someone requested information through the contact form. """ if provider is None: provider = get_broker() app = get_current_app() context = { 'broker': get_broker(), 'app': app, 'provider': provider, 'user': get_user_context(user), 'reason': reason } if user.pk is not None: context.update({ 'urls': { 'user': { 'profile': reverse('users_profile', args=(user, )) } } }) recipients, bcc = _notified_recipients(provider, "contact_requested_notice") LOGGER.debug("[signal] contact_requested_notice(provider=%s, user=%s)", provider, user) if SEND_EMAIL: get_email_backend(connection=app.get_connection()).send( from_email=app.get_from_email(), reply_to=user.email, recipients=recipients, bcc=bcc, template='notification/user_contact.eml', context=context)
def charge_updated_notice(sender, charge, user, **kwargs): from saas.mixins import get_charge_context # Avoid import loop broker = charge.broker recipients, bcc = _notified_recipients(charge.customer, "charge_updated") broker_recipients, broker_bcc = _notified_recipients( broker, "charge_updated") context = get_charge_context(charge) if user and charge.created_by != user: context.update({'email_by': get_user_context(user)}) app = get_current_app() context.update({ 'broker': get_broker(), 'app': app, 'urls': { 'charge': { 'created_by': reverse('users_profile', args=(charge.created_by, )) } } }) if charge.is_paid: LOGGER.debug("[signal] charge_updated_notice(charge=%s, user=%s)", charge, user) if SEND_EMAIL: get_email_backend(connection=app.get_connection()).send( from_email=app.get_from_email(), recipients=recipients, bcc=bcc + broker_recipients + broker_bcc, reply_to=broker_recipients[0], template='notification/charge_receipt.eml', context=context)
def expires_soon_notice(sender, subscription, nb_days, **kwargs): LOGGER.debug("[signal] expires_soon_notice("\ " subscription=%s, nb_days=%s)", subscription, nb_days) recipients, bcc = _notified_recipients(subscription.organization, 'expires_soon') if SEND_EMAIL and recipients: broker = get_broker() broker_recipients, broker_bcc = _notified_recipients( broker, 'expires_soon') site = get_current_site() app = get_current_app() back_url = "%s?plan=%s" % (site.as_absolute_uri( reverse('saas_organization_cart', args=(subscription.organization, ))), subscription.plan) kwargs = {} if broker.email and broker.email != site.get_from_email(): kwargs = {'reply_to': broker.email} get_email_backend(connection=site.get_email_connection()).send( from_email=site.get_from_email(), recipients=recipients, bcc=bcc + broker_recipients + broker_bcc, template='notification/expires_soon.eml', context={ 'broker': get_broker(), 'app': app, 'back_url': back_url, 'nb_days': nb_days, 'organization': subscription.organization, 'plan': subscription.plan, 'provider': subscription.plan.organization }, **kwargs)
def order_executed_notice(sender, invoiced_items, user, **kwargs): broker = get_broker() invoiced_items = list(invoiced_items) organization = (invoiced_items[0].dest_organization if invoiced_items else None) recipients, bcc = _notified_recipients(organization, 'order_executed') broker_recipients, broker_bcc = _notified_recipients( broker, 'order_executed') app = get_current_app() LOGGER.debug("[signal] order_executed_notice(invoiced_items=%s, user=%s)", [invoiced_item.pk for invoiced_item in invoiced_items], user) if SEND_EMAIL: context = { 'broker': broker, 'app': app, 'provider': broker, 'organization': organization, 'invoiced_items': invoiced_items, 'created_by': user } if user: context.update({ 'urls': { 'order': { 'created_by': reverse('users_profile', args=(user, )) } } }) get_email_backend(connection=app.get_connection()).send( from_email=app.get_from_email(), recipients=recipients, bcc=bcc + broker_recipients + broker_bcc, reply_to=broker_recipients[0], template='notification/order_executed.eml', context=context)
def post(self, request, *args, **kwargs):#pylint:disable=unused-argument """ Sends a test notification e-mail. **Tags: themes **Example .. code-block:: http POST /api/notifications/contact_requested_notice/ HTTP/1.1 """ try: app = get_current_app() get_email_backend(connection=app.get_connection()).send( from_email=app.get_from_email(), recipients=[self.request.user.email], template="notification/%s.eml" % self.kwargs.get( 'template', None), context=get_test_email_context()) except TemplateDoesNotExist: return Response({"details": _("Problem with template. Could not send test email.")}, status=status.HTTP_400_BAD_REQUEST) return Response( {"details": _("Test email sent to %(email)s") % { 'email': request.user.email}})
def subscribe_req_accepted_notice(sender, subscription, request_key, request=None, **kwargs): subscriber = subscription.organization recipients, bcc = _notified_recipients(subscriber, "subscribe_req_accepted_notice") LOGGER.debug("[signal] subscribe_req_accepted_notice("\ " subscription=%s, request_key=%s)", subscription, request_key) if SEND_EMAIL and recipients: site = get_current_site() app = get_current_app() user_context = get_user_context(request.user if request else None) get_email_backend(connection=site.get_email_connection()).send( from_email=site.get_from_email(), recipients=recipients, bcc=bcc, reply_to=user_context['email'], template='notification/subscription_request_accepted.eml', context={ 'broker': get_broker(), 'app': app, 'back_url': site.as_absolute_uri( reverse('organization_app', args=(subscriber, ))), 'organization': subscriber, 'plan': subscription.plan, 'user': user_context })
def claim_code_notice(sender, subscriber, claim_code, user, **kwargs): cart_items = CartItem.objects.by_claim_code(claim_code) provider = CartItem.objects.provider(cart_items) site = get_current_site() app = get_current_app() LOGGER.debug("[signal] claim_code_notice(subscriber=%s, claim_code=%s,"\ " user=%s)", subscriber, claim_code, user) if SEND_EMAIL: get_email_backend(connection=app.get_connection()).send( from_email=app.get_from_email(), recipients=[subscriber.email], reply_to=user.email, template='notification/claim_code_generated.eml', context={ 'broker': get_broker(), 'app': app, 'urls': { 'cart': site.as_absolute_uri(reverse('saas_cart')) }, 'subscriber': subscriber, 'provider': provider, 'claim_code': claim_code, 'cart_items': cart_items, 'user': get_user_context(user) })
def user_verification_notice(sender, user, request, back_url, expiration_days, **kwargs): """ A user has reset her password. """ broker = get_broker() app = get_current_app() LOGGER.debug("[signal] user_verification_notice(user=%s, back_url=%s,"\ " expiration_days=%s)", user, back_url, expiration_days) if SEND_EMAIL: get_email_backend(connection=app.get_connection()).send( from_email=app.get_from_email(), recipients=[user.email], template='notification/verification.eml', context={ 'request': request, # Without ``app`` we donot set the color correctly in # in notification/base.html, thus ending with an error # in premailer. 'broker': get_broker(), 'app': app, 'provider': broker, 'user': get_user_context(user), 'back_url': back_url, 'expiration_days': expiration_days })
def user_relation_added_notice(sender, role, reason=None, **kwargs): user = role.user organization = role.organization if user.email != organization.email: if user.email: back_url = reverse('organization_app', args=(organization, )) if has_invalid_password(user): if role.grant_key: contact, _ = Contact.objects.get_or_create_token( user, verification_key=role.grant_key) else: # The User is already in the system but the account # has never been activated. contact, _ = Contact.objects.get_or_create_token( user, verification_key=organization.generate_role_key(user)) user.save() back_url = "%s?next=%s" % (reverse( 'registration_activate', args=(contact.verification_key, )), back_url) elif role.grant_key: back_url = reverse('saas_role_grant_accept', args=(user, role.grant_key)) site = get_current_site() app = get_current_app() context = { 'broker': get_broker(), 'app': app, 'back_url': site.as_absolute_uri(back_url), 'organization': organization, 'role': role.role_description.title, 'reason': reason if reason is not None else "", 'user': get_user_context(user) } reply_to = organization.email request_user = kwargs.get('request_user', None) if request_user: reply_to = request_user.email context.update( {'request_user': get_user_context(request_user)}) LOGGER.debug("[signal] user_relation_added_notice(role=%s,"\ " reason=%s)", role, reason) if SEND_EMAIL: get_email_backend(connection=app.get_connection()).send( from_email=app.get_from_email(), recipients=[user.email], reply_to=reply_to, template=[("notification/%s_role_added.eml" % role.role_description.slug), "notification/role_added.eml"], context=context) else: LOGGER.warning( "%s will not be notified being added to %s"\ "because e-mail address is invalid.", user, organization)
def subscribe_grant_created_notice(sender, subscription, reason=None, invite=False, request=None, **kwargs): if subscription.grant_key: user_context = get_user_context(request.user if request else None) organization = subscription.organization if organization.email: site = get_current_site() app = get_current_app() back_url = site.as_absolute_uri( reverse('subscription_grant_accept', args=( organization, subscription.grant_key, ))) manager = organization.with_role(saas_settings.MANAGER).first() # The following line could as well be `if invite:` if has_invalid_password(manager): # The User is already in the system but the account # has never been activated. contact, _ = Contact.objects.get_or_create_token( manager, verification_key=organization.generate_role_key(manager)) manager.save() back_url = "%s?next=%s" % (reverse( 'registration_activate', args=(contact.verification_key, )), back_url) LOGGER.debug("[signal] subscribe_grant_created_notice("\ " subscription=%s, reason=%s, invite=%s)", subscription, reason, invite) if SEND_EMAIL: get_email_backend(connection=app.get_connection()).send( from_email=app.get_from_email(), recipients=[organization.email], reply_to=user_context['email'], template='notification/subscription_grant_created.eml', context={ 'broker': get_broker(), 'app': app, 'back_url': back_url, 'organization': organization, 'plan': subscription.plan, 'reason': reason if reason is not None else "", 'invite': invite, 'user': user_context }) else: LOGGER.warning( "%s will not be notified of a subscription grant to %s"\ "because e-mail address is invalid.", organization, subscription.plan)
def perform_create(self, serializer): get_email_backend().send( recipients=[admin[1] for admin in django_settings.ADMINS], reply_to=serializer.validated_data['email'], template='notification/request_demo.eml', context={ 'project': self.project, 'email': serializer.validated_data['email'], 'phone': serializer.validated_data['phone'], 'body': serializer.validated_data['body'] })
def application_created_notice(sender, application, url, **kwargs): #pylint:disable=unused-argument get_email_backend().send( recipients=get_lihtc_property_email(application.lihtc_property), reply_to=settings.DEFAULT_FROM_EMAIL, template='notification/application_created.eml', context={'site': application.lihtc_property, 'provider': { 'email': settings.DEFAULT_FROM_EMAIL, 'phone': "17084622842"}, 'application': application, 'back_url': url})
def _send_notification_email(from_site, recipients, template, context=None, reply_to=None, bcc=None): """ Sends a notification e-mail using the current site connection, defaulting to sending an e-mail to broker profile managers if there is any problem with the connection settings. """ #pylint:disable=too-many-arguments lang_code = None contact = Contact.objects.filter( email__in=recipients).order_by('email').first() if contact: lang_code = contact.lang try: with translation.override(lang_code): get_email_backend(connection=from_site.get_email_connection()).send( from_email=from_site.get_from_email(), recipients=recipients, reply_to=reply_to, bcc=bcc, template=template, context=context) except smtplib.SMTPException as err: LOGGER.warning( "[signal] problem sending email from %s on connection for %s. %s", from_site.get_from_email(), from_site, err) context.update({'errors': [_("There was an error sending"\ " the following email to %(recipients)s. This is most likely due to"\ " a misconfiguration of the e-mail notifications whitelabel settings"\ " for your site %(site)s.") % { 'recipients': recipients, 'site': from_site.as_absolute_uri()}]}) #pylint:disable=unused-variable notified_on_errors, notused = _notified_recipients( get_organization_model().objects.using(from_site._state.db).get( pk=from_site.account_id), "") if notified_on_errors: get_email_backend( connection=get_connection_base(fail_silently=True)).send( from_email=settings.DEFAULT_FROM_EMAIL, recipients=notified_on_errors, template=template, context=context) except Exception as err: # Something went horribly wrong, like the email password was not # decrypted correctly. We want to notifiy the operations team # but the end user shouldn't see a 500 error as a result # of notifications sent in the HTTP request pipeline. LOGGER.exception(err)
def user_relation_added_notice(sender, role, reason=None, **kwargs): user = role.user organization = role.organization if user.email != organization.email: if user.email: back_url = reverse('organization_app', args=(organization, )) if role.grant_key: back_url = reverse('saas_role_grant_accept', args=(role.grant_key, )) if has_invalid_password(user): reason = _("You have been invited to create an account"\ " to join %(organization)s.") % { 'organization': role.organization.printable_name} Contact.objects.update_or_create_token(user, reason=reason) site = get_current_site() app = get_current_app() context = { 'broker': get_broker(), 'app': app, 'back_url': site.as_absolute_uri(back_url), 'organization': organization, 'role': role.role_description.title, 'reason': reason if reason is not None else "", 'user': get_user_context(user) } reply_to = organization.email request_user = kwargs.get('request_user', None) if request_user: reply_to = request_user.email context.update( {'request_user': get_user_context(request_user)}) LOGGER.debug("[signal] user_relation_added_notice(role=%s,"\ " reason=%s)", role, reason) if SEND_EMAIL: get_email_backend(connection=app.get_connection()).send( from_email=app.get_from_email(), recipients=[user.email], reply_to=reply_to, template=[("notification/%s_role_added.eml" % role.role_description.slug), "notification/role_added.eml"], context=context) else: LOGGER.warning( "%s will not be notified being added to %s"\ "because e-mail address is invalid.", user, organization)
def organization_updated_notice(sender, organization, changes, user, **kwargs): if not changes: return recipients, _ = _notified_recipients(organization, 'organization_updated') LOGGER.info("%s updated", organization, extra={ 'event': 'update-fields', 'organization': str(organization), 'changes': changes }) if SEND_EMAIL and recipients: broker = get_broker() site = get_current_site() app = get_current_app() broker_recipients, broker_bcc = _notified_recipients( broker, 'organization_updated') kwargs = {} if broker.email and broker.email != site.get_from_email(): kwargs = {'reply_to': broker.email} get_email_backend(connection=site.get_email_connection()).send( from_email=site.get_from_email(), recipients=recipients, bcc=broker_recipients + broker_bcc, template='notification/organization_updated.eml', context={ 'broker': broker, 'app': app, 'user': get_user_context(user), 'organization': organization, 'changes': changes, 'urls': { 'user': { 'profile': site.as_absolute_uri( reverse('users_profile', args=(user, ))) }, 'organization': { 'profile': site.as_absolute_uri( reverse('saas_organization_profile', args=(organization, ))) } } }, **kwargs)
def on_answer_posted(sender, comment, request, *args, **kwargs): question_ctype = ContentType.objects.get_for_model(get_question_model()) if comment.content_type == question_ctype: question = comment.content_object back_url = request.build_absolute_uri(request.POST.get('next', "")) # back_url = request.build_absolute_uri( # reverse('summary', args=("/%s" % question,))) get_email_backend().send( recipients=[notified.email for notified in Follow.objects.get_followers(question)], template='notification/question_updated.eml', context={'request': request, 'question': question, 'back_url': back_url, 'site': get_site(request)}) # Subscribe the commenting user to this question Follow.objects.subscribe(question, user=request.user)
def subscribe_req_created_notice(sender, subscription, reason=None, request=None, **kwargs): if subscription.request_key: user_context = get_user_context(request.user if request else None) organization = subscription.organization if organization.email: site = get_current_site() app = get_current_app() LOGGER.debug("[signal] subscribe_req_created_notice("\ " subscription=%s, reason=%s)", subscription, reason) if SEND_EMAIL: get_email_backend(connection=app.get_connection()).send( from_email=app.get_from_email(), recipients=[organization.email], reply_to=user_context['email'], template='notification/subscription_request_created.eml', context={ 'broker': get_broker(), 'app': app, 'back_url': site.as_absolute_uri( reverse('subscription_request_accept', args=( organization, subscription.request_key, ))), 'organization': organization, 'plan': subscription.plan, 'reason': reason if reason is not None else "", 'user': user_context }) else: LOGGER.warning( "%s will not be notified of a subscription request to %s"\ "because e-mail address is invalid.", organization, subscription.plan)
def post(self, request, *args, **kwargs): try: app = get_current_app() get_email_backend(connection=app.get_connection()).send( from_email=app.get_from_email(), recipients=[self.request.user.email], template="notification/%s.eml" % self.kwargs.get('template', None), context=get_test_email_context()) except TemplateDoesNotExist: return Response( { "details": "Problem with template. Could not send test email." }, status=status.HTTP_400_BAD_REQUEST) return Response( {"details": "Test email sent to %s" % request.user.email})
def on_assessment_completed(assessment, path, notified, *args, **kwargs): request = kwargs.get('request', None) reason = kwargs.get('reason', None) recipients = [manager.email for manager in notified.with_role('manager')] if not recipients: # Avoids 500 errors when no managers recipients = [settings.DEFAULT_FROM_EMAIL] back_url = request.build_absolute_uri( reverse('scorecard_organization', args=(assessment.account, assessment, path))) get_email_backend().send(recipients=recipients, template='notification/assessment_completed.eml', context={ 'organization': assessment.account, 'reason': reason, 'back_url': back_url, 'site': get_site(request) })
def user_registered_notice(sender, user, **kwargs): """ A new user has registered (frictionless or completely) """ broker = get_broker() recipients, bcc = _notified_recipients(broker, "user_registered_notice") app = get_current_app() LOGGER.debug("[signal] user_registered_notice(user=%s)", user) if SEND_EMAIL: get_email_backend(connection=app.get_connection()).send( from_email=app.get_from_email(), recipients=recipients, bcc=bcc, template='notification/user_registered.eml', context={ 'broker': get_broker(), 'app': app, 'user': get_user_context(user) })
def role_grant_accepted_notice(sender, role, grant_key, request=None, **kwargs): user_context = get_user_context(request.user if request else None) recipients, bcc = _notified_recipients(role.organization, "role_grant_accepted_notice") if recipients: site = get_current_site() app = get_current_app() LOGGER.debug("[signal] role_grant_accepted_notice("\ " role=%s, grant_key=%s)", role, grant_key) if SEND_EMAIL: get_email_backend(connection=app.get_connection()).send( from_email=app.get_from_email(), recipients=[role.organization.email] + recipients, bcc=bcc, reply_to=user_context['email'], template='notification/role_grant_accepted.eml', context={ 'broker': get_broker(), 'app': app, 'back_url': site.as_absolute_uri( reverse('saas_role_detail', args=(role.organization, role.role_description))), 'organization': role.organization, 'role': role.role_description.title, 'user': user_context }) else: LOGGER.warning( "%s will not be notified that the %s role of %s"\ " was accepted because e-mail address is invalid.", role.organization, role.role_description, request.user)
def card_updated_notice(sender, organization, user, old_card, new_card, **kwargs): recipients, bcc = _notified_recipients(organization) app = get_current_app() LOGGER.debug("[signal] card_updated_notice(organization=%s, user=%s,"\ "old_card=%s, new_card=%s)", organization, user, old_card, new_card) if SEND_EMAIL: get_email_backend(connection=app.get_connection()).send( from_email=app.get_from_email(), recipients=recipients, bcc=bcc, template='notification/card_updated.eml', context={ 'broker': get_broker(), 'app': app, 'organization': organization, 'user': get_user_context(user), 'old_card': old_card, 'new_card': new_card })
def user_reset_password_notice(sender, user, request, back_url, expiration_days, **kwargs): """ A user has reset her password. """ app = get_current_app() LOGGER.debug("[signal] user_reset_password_notice(user=%s, back_url=%s,"\ " expiration_days=%s)", user, back_url, expiration_days) if SEND_EMAIL: get_email_backend(connection=app.get_connection()).send( from_email=app.get_from_email(), recipients=[user.email], template='notification/password_reset.eml', context={ 'request': request, 'broker': get_broker(), 'app': app, 'back_url': back_url, 'expiration_days': expiration_days, 'user': get_user_context(user) })
def contact_requested_notice(sender, provider, user, reason, **kwargs): """ Someone requested information through the contact form. """ if provider is None: provider = get_broker() app = get_current_app() context = { 'broker': get_broker(), 'app': app, 'provider': provider, 'user': get_user_context(user), 'reason': reason } if user.pk is not None: context.update({ 'urls': { 'user': { 'profile': reverse('users_profile', args=(user, )) } } }) recipients, bcc = _notified_recipients(provider, "contact_requested_notice") # We are hanlding `recipients` a bit differently here because contact # requests are usually meant to be sent to a ticketing system. if provider.email: recipients = [provider.email] bcc = recipients + bcc LOGGER.debug("[signal] contact_requested_notice(provider=%s, user=%s)", provider, user) if SEND_EMAIL and recipients: site = get_current_site() get_email_backend(connection=site.get_email_connection()).send( from_email=site.get_from_email(), reply_to=user.email, recipients=recipients, bcc=bcc, template='notification/user_contact.eml', context=context)