Beispiel #1
0
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)
Beispiel #2
0
 def get_email_connection(self):
     kwargs = {}
     if self.email_host:
         kwargs['host'] = self.email_host
     if self.email_port:
         kwargs['port'] = self.email_port
     if self.email_host_user:
         kwargs['username'] = self.email_host_user
     if self.email_host_password:
         kwargs['password'] = self.get_email_host_password()
     return get_connection_base(**kwargs)
Beispiel #3
0
 def get_email_connection(self):
     kwargs = {}
     if self.email_host:
         kwargs['host'] = self.email_host
     if self.email_port:
         kwargs['port'] = self.email_port
     if self.email_host_user:
         kwargs['username'] = self.email_host_user
     if self.email_host_password:
         kwargs['password'] = self.get_email_host_password()
     return get_connection_base(**kwargs)
Beispiel #4
0
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)
Beispiel #5
0
 def get_connection(self):
     #pylint:disable=no-self-use
     kwargs = {}
     return get_connection_base(**kwargs)
Beispiel #6
0
 def get_connection(self):
     #pylint:disable=no-self-use
     kwargs = {}
     return get_connection_base(**kwargs)