Beispiel #1
0
 def send_admin_order_confirm_emails(self, order_items, clover_order, clover_payment):
     admins = User.objects.filter(is_superuser=True)
     for admin in admins:
         mail = EmailMessage(to=[
             {
                 'address': admin.email,
                 'substitution_data': {
                     'first_name': admin.first_name,
                     'client_first': self.first_name,
                     'client_last': self.last_name,
                     'client_email': self.email,
                     'client_address': self.address,
                     'client_postal': self.postal_code,
                     'client_city': self.city,
                     'client_phone': self.phone,
                     'order_created': self.created.strftime('%m/%d/%y'),
                     'clover_order_id': clover_order['id'],
                     'clover_pay_id': clover_payment['paymentId'],
                     'order_items': str(order_items)
                 }
             }
         ], from_email='*****@*****.**',
             subject='New Order {} Confirmation | Flower Flour'.format(clover_order['id']))
         mail.template = 'admin-order-confirm'
         mail.send()
def forgot_password(request):
    reset_message = 'You will receive an email with reset instructions shortly'
    not_found_message = 'We could not find a user for that email address'

    if request.method == 'POST':
        form = forms.ForgotPasswordForm(request.POST)

        if form.is_valid():
            email = form.cleaned_data['email']
            user = KagisoUser.get_user_from_auth_db(email)

            if user:
                msg = EmailMessage()
                msg.to = [user.email]
                msg.from_email = get_setting(settings.AUTH_FROM_EMAIL, request)
                msg.subject = 'Password Reset'
                msg.template = get_setting(
                    settings.PASSWORD_RESET_EMAIL_TEMPLATE, request)
                msg.substitution_data = {
                    'link':
                    request.build_absolute_uri(reverse('reset_password')),
                    'token': user.generate_reset_password_token(),
                    'user_id': user.id
                }
                msg.send()

                messages.success(request, reset_message)
                return HttpResponseRedirect(reverse('forgot_password'))
            else:
                messages.error(request, not_found_message)
                return HttpResponseRedirect(reverse('forgot_password'))
    else:
        form = forms.ForgotPasswordForm()

    return render(request, 'kagiso_auth/forgot_password.html', {'form': form})
Beispiel #3
0
 def send_client_email(self):
     mail = EmailMessage(to=[{
         'address': self.email,
         'substitution_data': {
             'name': self.name,
             'subject': self.subject,
             'message': self.message,
             'phone': self.phone
         }
     }],
                         from_email='*****@*****.**')
     mail.template = 'contact-email'
     mail.send()
def _send_confirmation_email(user, request):
    msg = EmailMessage()
    msg.to = [user.email]
    msg.from_email = get_setting(settings.AUTH_FROM_EMAIL, request)
    msg.subject = 'Confirm Your Account'
    msg.template = get_setting(settings.SIGN_UP_EMAIL_TEMPLATE, request)
    msg.substitution_data = {
        'link': request.build_absolute_uri(reverse('confirm_account')),
        'token': user.confirmation_token,
        'user_id': user.id,
        'first_name': user.first_name,
        'next': request.GET.get('next', '/')
    }
    msg.send()
def _send_confirmation_email(user, request):
    msg = EmailMessage()
    msg.to = [user.email]
    msg.from_email = get_setting(settings.AUTH_FROM_EMAIL, request)
    msg.subject = 'Confirm Your Account'
    msg.template = get_setting(settings.SIGN_UP_EMAIL_TEMPLATE, request)
    msg.substitution_data = {
        'link': request.build_absolute_uri(reverse('confirm_account')),
        'token': user.confirmation_token,
        'user_id': user.id,
        'first_name': user.first_name,
        'next': request.GET.get('next', '/')
    }
    msg.send()
Beispiel #6
0
 def send_client_custom_cake_confirm_emails(self, cake):
     mail = EmailMessage(to=[
         {
             'address': self.email,
             'substitution_data': {
                 'first_name': self.first_name,
                 'name': '{} {}'.format(self.first_name, self.last_name),
                 'phone': self.phone,
                 'created': self.created.strftime('%m/%d/%y'),
                 'cake': str(cake)
             }
         }
     ], from_email='*****@*****.**')
     mail.template = 'client-custom-cake-confirm'
     mail.send()
Beispiel #7
0
def send_email(recipients, subject, template_id, substitutions):
    """
    Send an email to one or more recipients.
    """
    for recipient in recipients:
        logger.debug("Sending email to: %s", recipient)
        email = EmailMessage(
            to=[{
                "address": recipient.email,
                "substitution_data": substitutions
            }],
            subject=subject,
        )
        email.template = template_id
        email.send()
Beispiel #8
0
 def send_admin_emails(self):
     admins = User.objects.filter(is_superuser=True)
     for admin in admins:
         mail = EmailMessage(to=[{
             'address': admin.email,
             'substitution_data': {
                 'name': admin.first_name,
                 'client_name': self.name,
                 'subject': self.subject,
                 'message': self.message,
                 'phone': self.phone
             }
         }],
                             from_email='*****@*****.**')
         mail.template = 'contact-confirm-admin'
         mail.send()
Beispiel #9
0
 def send_admin_custom_cake_confirm_emails(self, cake):
     admins = User.objects.filter(is_superuser=True)
     for admin in admins:
         mail = EmailMessage(to=[
             {
                 'address': admin.email,
                 'substitution_data': {
                     'first_name': admin.first_name,
                     'name': '{} {}'.format(self.first_name, self.last_name),
                     'phone': self.phone,
                     'created': self.created.strftime('%m/%d/%y'),
                     'cake': str(cake)
                 }
             }
         ], from_email='*****@*****.**')
         mail.template = 'admin-custom-cake-confirm'
         mail.send()
Beispiel #10
0
 def send_client_order_confirm_email(self, order_items, clover_order, clover_payment):
     mail = EmailMessage(to=[
         {
             'address': self.email,
             'substitution_data': {
                 'first_name': self.first_name,
                 'order_id': clover_order['id'],
                 'currency': clover_order['currency'],
                 'created': self.created.strftime('%m/%d/%y'),
                 'payment_id': clover_payment['paymentId'],
                 'mail_address': self.address,
                 'postal': self.postal_code,
                 'city': self.city,
                 'order_items': str(order_items)
             }
         }
     ], from_email='*****@*****.**')
     mail.template = 'order-confirm'
     mail.send()
def forgot_password(request):
    reset_message = 'You will receive an email with reset instructions shortly'
    not_found_message = 'We could not find a user for that email address'

    if request.method == 'POST':
        form = forms.ForgotPasswordForm(request.POST)

        if form.is_valid():
            email = form.cleaned_data['email']
            user = KagisoUser.get_user_from_auth_db(email)

            if user:
                msg = EmailMessage()
                msg.to = [user.email]
                msg.from_email = get_setting(settings.AUTH_FROM_EMAIL, request)
                msg.subject = 'Password Reset'
                msg.template = get_setting(
                    settings.PASSWORD_RESET_EMAIL_TEMPLATE,
                    request
                )
                msg.substitution_data = {
                    'link': request.build_absolute_uri
                    (reverse('reset_password')),
                    'token': user.generate_reset_password_token(),
                    'user_id': user.id
                }
                msg.send()

                messages.success(request, reset_message)
                return HttpResponseRedirect(reverse('forgot_password'))
            else:
                messages.error(request, not_found_message)
                return HttpResponseRedirect(reverse('forgot_password'))
    else:
        form = forms.ForgotPasswordForm()

    return render(
        request,
        'kagiso_auth/forgot_password.html',
        {'form': form}
    )
Beispiel #12
0
def send_mail(recipient_list,
              template_name,
              substitution_data,
              blind_recipient_list=None):
    """
    Just send an email with Sparkpost (Sparkpost Template)
    :param recipient_list: list
    :param template_name: str
    :param substitution_data: dict
    :param blind_recipient_list: list
    :return:
    """
    if not blind_recipient_list:
        blind_recipient_list = []

    msg = EmailMessage(to=[{
        'address': recipient,
        'substitution_data': substitution_data
    } for recipient in recipient_list],
                       bcc=blind_recipient_list)
    msg.template = template_name
    msg.send()