Пример #1
0
def email_verification(request):
    '''
        This method is for sending the verification link to the user through email.
        Currently it sends link like https://127.0.0.1:8000 encrypted user id.

    '''
    #demo values
    user = {
        'id': '1',
        'name': 'fuhad',
        'template': 'user_activation.html',
        'subject': 'Activate your account',
        'sender': '*****@*****.**',
        'receiver': ['*****@*****.**'],
        'status': 'False',
        'current_site': '127.0.0.1:8000'
    }

    company = {
        'name': 'Company Name',
        'logo': 'logo_img_src',
        'banner': 'banner_img_src',
        'subject': 'Thank you for purchasing',
        'sender': '*****@*****.**',
        'receiver': ['*****@*****.**']
    }
    config = get_email_config()
    # backend = EmailBackend(host='smtp.gmail.com', port=config['email_port'], username=config['email_host_user'],
    # password=config['email_host_password'], use_tls=config['Tls_value'],fail_silently=False)

    template = render_to_string(
        user['template'], {
            'name': user['name'],
            'user_email': user['receiver'],
            'domain': user['current_site'],
            'logo': company['logo'],
            'banner': company['banner'],
            'company_name': company['name'],
            'uid': urlsafe_base64_encode(force_bytes(user['id']))
        })
    text_content = strip_tags(template)

    email_message = EmailMultiAlternatives(user['subject'], text_content,
                                           user['sender'], user['receiver'])
    email_message.fail_silently = False
    email_message.attach_alternative(template, "text/html")
    email_message.send()
    try:
        email_message.send()
        return render(request, 'index.html')
    except:
        return render(request, 'error.html', {'error': 'Internal server'})
Пример #2
0
def success(request):
    del request.session['bag']
    invoice = Invoice.objects.get(
        checkout_session_id=request.GET.get('session_id').replace(' ', ''))

    subject = 'Your invoice'
    html_message = render_to_string('email.html', {'invoice': invoice})
    plain_message = strip_tags(html_message)
    from_email = settings.EMAIL_HOST_USER
    to = invoice.user.email
    copy = "*****@*****.**"

    msg = EmailMultiAlternatives(subject, subject, from_email, [to, copy])
    msg.attach_alternative(html_message, "text/html")
    msg.fail_silently = False
    msg.send()
    message = f'{"Thanks For Choosing Hunt-Interiors"}'

    return render(request, 'bag/success.html', {'message': message})
Пример #3
0
    def post(self, request):
        try:
            context = {
                "name": request.data.get("name"),
                "subject": request.data.get("subject"),
                "email": request.data.get("email"),
                "message": request.data.get("message")
            }

            template = render_to_string('email.html', context)
            text_template = render_to_string('email.txt', context)

            msg = EmailMultiAlternatives(context.get("subject"), text_template,
                                         settings.EMAIL_HOST_USER,
                                         ["*****@*****.**"])
            msg.attach_alternative(template, "text/html")
            msg.fail_silently = False
            msg.send()

        except:
            return Response(status=403,
                            data={"error_message": "Message Failed To Send"})

        return Response({"msg": "Message Sent Successfully"})