Exemplo n.º 1
0
def send_email(email_to, subject, body):
    django_send_email(
        subject=subject,
        message=body,
        from_email='*****@*****.**',
        recipient_list=[email_to],
        html_message=body,
        fail_silently=False,
    )
    return True
Exemplo n.º 2
0
def send_email(subject, message):
    conf = EmailConf.get_instance()
    settings.EMAIL_HOST = conf.email_host
    settings.EMAIL_PORT = conf.email_port
    if conf.email_user and conf.email_password:
        settings.EMAIL_HOST_USER = conf.email_user
        settings.EMAIL_HOST_PASSWORD = conf.email_password
        settings.EMAIL_USE_TLS = conf.tls_support

    if conf.active:
        socket.setdefaulttimeout(DEFAULT_SOCKET_TIMEOUT)
        django_send_email(subject, message, conf.email_user, [conf.send_to])
Exemplo n.º 3
0
def send_email(subject, message):
    conf = EmailConf.get_instance()
    settings.EMAIL_HOST = conf.email_host
    settings.EMAIL_PORT = conf.email_port
    if conf.email_user and conf.email_password:
        settings.EMAIL_HOST_USER = conf.email_user
        settings.EMAIL_HOST_PASSWORD = conf.email_password
        settings.EMAIL_USE_TLS = conf.tls_support

    if conf.active:
        socket.setdefaulttimeout(DEFAULT_SOCKET_TIMEOUT)
        django_send_email(subject, message, conf.email_user, [conf.send_to])
Exemplo n.º 4
0
def send_mail(to_emails,
              from_email=settings.DEFAULT_FROM_EMAIL,
              subject='No subject',
              message=None,
              template=None,
              context=None,
              fail_silently=True):
    """Send email using Django's send_email function but setting a number of defaults and adding a
    prefix in the subject. It also renders a template with a context if provided."""
    if not subject.startswith(settings.EMAIL_SUBJECT_PREFIX):
        subject = settings.EMAIL_SUBJECT_PREFIX + subject
    if template is not None and context is not None:
        message = render_to_string(template, context)
    if type(to_emails) is not list and type(to_emails) is not tuple:
        to_emails = (to_emails, )
    django_send_email(subject, message, from_email, to_emails, fail_silently)
Exemplo n.º 5
0
    def send_to(self, email_addresses):
        """
        Отпрака письма
        """
        if not email_addresses:
            return

        if isinstance(email_addresses, basestring):
            email_addresses = [email_addresses]

        if settings.USE_DJANGO_SEND_MAIL:
            django_send_email(self.subject,
                              self.content,
                              settings.DEFAULT_FROM_EMAIL,
                              tuple(email_addresses),
                              html_message=self.html)
        else:
            for email_address in email_addresses:
                EmailSender.send_mail(_from=settings.DEFAULT_FROM_EMAIL,
                                      _to=email_address,
                                      _subject=self.subject,
                                      _content=self.content)
Exemplo n.º 6
0
    def perform_destroy(self, instance):
        booking, deleted = instance.delete()

        if deleted:
            reserved_users = Reserve.objects.filter(
                row=instance.row,
                column=instance.column,
                seance=instance.seance).values_list('id', 'user__email')

            for key, value in reserved_users:
                send_mail = django_send_email(
                    'Cinema Booking',
                    'You can booking your reserve seat',
                    '*****@*****.**',
                    [value],
                    fail_silently=False,
                )

                if send_mail:
                    Reserve.objects.get(pk=key).delete()
Exemplo n.º 7
0
def send_email(topic, template_path, context_dict, emails):
    context = Context(context_dict)
    render = get_template(template_path).render(context)

    django_send_email(topic, render, "*****@*****.**", emails)
Exemplo n.º 8
0
def send_email(email, subject, content, plain_content=""):
    return django_send_email(
        subject, plain_content, settings.EMAIL_HOST_USER, [email], html_message=content, fail_silently=True
    )
Exemplo n.º 9
0
def create_notification(description,
                        user,
                        message_type,
                        category=None,
                        link=None,
                        link_prop=None,
                        request=None,
                        send_email=False,
                        email_subject=None,
                        email_template=None,
                        email_context={}):
    """
    Create a notification for provided user, and send email notification if it's set

    There is two default setting you can configurate on django settings

    - NOTIFICATION_DEFAULT_SUBJECT
    - NOTIFICATION_DEFAULT_TEMPLATE

    All settings has a default value provided by django-gentelella-widgets but you can overwrite it

    :param description: description to show
    :param user: user to be notified
    :param message_type: type of message available options (info, default, success, warning, danger) there is no priority here yet
    :param category: used for group notifications (not required)
    :param link: complete url or reverse name (see django reverse)
    :param link_prop: when is set, the link is take as reverse name, you need to provide dict of args and kwargs
    :param request: it's django request used on email and for make a complete uri on reverse
    :param send_email: True/False specify you want to send a email notification
    :param email_subject: alternative subject message
    :param email_template: alternative email template
    :param email_context: extra context for email template
    :return: notification object
    """

    if message_type not in message_type_default:
        raise ValueError("Message type are not valid (options: %s)" %
                         ("".join(message_type_default)))
    if category is None:
        category = uuid.uuid4()
    if link_prop is not None:
        if request is None:
            raise ValueError('Request is required when link_prop is set')
        if 'kwargs' not in link_prop or 'args' not in link_prop:
            raise ValueError(
                'args and kwargs are required for reverse function')
        link = get_site_url(request, link, **link_prop)

    dev = Notification.objects.create(state='visible',
                                      user=user,
                                      message_type=message_type,
                                      description=description,
                                      link=link,
                                      category=category)

    if send_email:
        if email_subject is None:
            email_subject = settings.NOTIFICATION_DEFAULT_SUBJECT
        if email_template is None:
            email_template = settings.NOTIFICATION_DEFAULT_TEMPLATE
        email_context['object'] = dev
        if user.email:
            django_send_email(
                email_subject,
                _('This is a html email, please use a visor with HTML support'
                  ),
                djsettings.DEFAULT_FROM_EMAIL, [user.email],
                fail_silently=False,
                html_message=render_to_string(email_template,
                                              context=email_context,
                                              request=request))

    return dev