def get_connection(backend=None, template_prefix=None, template_suffix=None,
                   fail_silently=False, **kwargs):
    """Load a templated e-mail backend and return an instance of it.

    If backend is None (default) settings.TEMPLATED_EMAIL_BACKEND is used.

    Both fail_silently and other keyword arguments are used in the
    constructor of the backend.
    """
    # This method is mostly a copy of the backend loader present in
    # django.core.mail.get_connection
    klass_path = backend or getattr(settings, 'TEMPLATED_EMAIL_BACKEND',
                                    TemplateBackend)
    if isinstance(klass_path, six.string_types):
        try:
            # First check if class name is omitted and we have module in settings
            mod = import_module(klass_path)
            klass_name = 'TemplateBackend'
        except ImportError as e:
            # Fallback to class name
            try:
                mod_name, klass_name = klass_path.rsplit('.', 1)
                mod = import_module(mod_name)
            except ImportError as e:
                raise ImproperlyConfigured(
                    ('Error importing templated email backend module %s: "%s"'
                     % (mod_name, e)))
        try:
            klass = getattr(mod, klass_name)
        except __HOLE__:
            raise ImproperlyConfigured(('Module "%s" does not define a '
                                        '"%s" class' % (mod_name, klass_name)))
    else:
        klass = klass_path

    return klass(fail_silently=fail_silently, template_prefix=template_prefix,
                 template_suffix=template_suffix, **kwargs)
dataset/ETHPy150Open BradWhittington/django-templated-email/templated_email/__init__.py/get_connection