Esempio n. 1
0
    def post(self, request, *args, **kwargs):
        if request.method == 'POST':
            serializer = InvitationMailSerializer(data=request.data)
            if serializer.is_valid():
                validated_data = serializer.validated_data

                site_name = validated_data.get('site_name')
                registration_page_link = validated_data.get(
                    'registration_link')
                recipient = validated_data.get('recipient')
                subject = 'User Invitation'
                description = validated_data.get('body')
                sender = validated_data.get('sender')
                html_content = render_to_string(
                    'invitation/email_invitation_template.html', {
                        'sender': sender,
                        'site_name': site_name,
                        'description': description,
                        'registration_link': registration_page_link
                    })
                content = Content("text/html", html_content)

                if validated_data.get('backend_type') == 'aws':
                    send_aws_mail(subject,
                                  '',
                                  sender,
                                  recipient,
                                  tmpl=html_content)
                    return Response(
                        {
                            'status': 'Successful',
                            'message': 'Invitation link successfully sent'
                        },
                        status=status.HTTP_200_OK)

                else:
                    send_mail(sender, recipient, subject, content)
                    return Response(
                        {
                            'status': 'Successful',
                            'message': 'Invitation link successfully sent'
                        },
                        status=status.HTTP_200_OK)

            else:
                return Response(
                    {
                        'status': 'failure',
                        'data': {
                            'message': 'Incorrect request format.',
                            'errors': serializer.errors
                        }
                    },
                    status=status.HTTP_400_BAD_REQUEST)
Esempio n. 2
0
    def post(self, request, *args, **kwargs):
        serializer = RegistrationMailSerializer(data=request.data)
        if serializer.is_valid():
            validated_data = serializer.validated_data
            context = {
                'sender': validated_data['sender'],
                'domain_name': validated_data['site_name'],
                'description': validated_data.get('body'),
                'site_url': validated_data['login_link']
            }
            subject = 'Welcome Esteemed Customer'
            recipient = validated_data['recipient']
            sender = validated_data['sender']
            html_content = get_template(
                'registration/welcome_mail_template.html').render(context)
            content = Content("text/html", html_content)

            if validated_data.get('backend_type') == 'aws':
                send_aws_mail(subject,
                              '',
                              sender,
                              recipient,
                              tmpl=html_content)
                return Response(
                    {
                        'status': 'Successful',
                        'message': 'Confirmation link successfully sent'
                    },
                    status=status.HTTP_200_OK)

            else:
                send_mail(sender, recipient, subject, content)
                return Response(
                    {
                        'status': 'Successful',
                        'message': 'Confirmation link successfully sent'
                    },
                    status=status.HTTP_200_OK)

        else:
            return Response(
                {
                    'status': 'failure',
                    'data': {
                        'message': 'Incorrect request format.',
                        'errors': serializer.errors
                    }
                },
                status=status.HTTP_400_BAD_REQUEST)
Esempio n. 3
0
    def post(self, request, *args, **kwargs):
        serializer= ConfirmationMailSerializer(data=request.data)
        if serializer.is_valid():
            validated_data = serializer.validated_data
            context = {
                'sender': validated_data['sender'],
                'domain_name': validated_data['site_name'],
                'description': validated_data.get('body'),
                'confirmation_link': validated_data['confirmation_link']
            }
            print(validated_data.get('backend_type'))
            subject = 'Account Confirmation'
            recipient = validated_data['recipient']
            sender = validated_data['sender']
            html_content = get_template('confirmation/confirmation_link_template.html').render(context)
            content = Content("text/html", html_content)

            if validated_data.get('backend_type') == 'aws':
                message = MIMEMultipart('alternative')
                message['Subject'] = subject
                message['From'] = sender
                message['To'] = recipient
                messageTemp = MIMEText(html_content, 'html')
                message.attach(messageTemp)
                send_aws_mail(subject, message.as_string(), sender, recipient)
                return Response({
                'message': 'Confirmation link successfully sent',
                'success': True,
                }, status=status.HTTP_200_OK)
                
            else:
                send_mail(sender, recipient, subject, content)
                return Response({
                'message': 'Confirmation link successfully sent by sendgrid',
                'success': True,
            }, status=status.HTTP_200_OK)
            
            
        else:
            return Response({
                'message': 'Incorrect request format.',
                'errors': serializer.errors,
                'success': False,
            }, status=status.HTTP_400_BAD_REQUEST)
Esempio n. 4
0
    def post(self, request, *args, **kwargs):
        serializer= SendCertificateSerializer(data=request.data)
        if serializer.is_valid():
            validated_data = serializer.validated_data
            context = {
                'sender': validated_data['sender'],
                'participant_name': validated_data.get('participant_name'),
                'certificate_link': validated_data['certificate_link']
            }
            subject = 'Certificate Of Achievement'
            recipient = validated_data['recipient']
            sender = validated_data['sender']
            html_content = get_template('send_certificate/certificate_link.html').render(context)
            content = Content("text/html", html_content)

            if validated_data.get('backend_type') == 'aws':
                send_aws_mail(subject, '', sender, recipient, tmpl=html_content)
                return Response({
                'status': 'Successful',
                'data': {
                    'message': 'Certificate link successfully sent'
                }
                
            }, status=status.HTTP_200_OK)
                
            else:
                send_mail(sender, recipient, subject, content)
                return Response({
                'status': 'Successful',
                'data': {
                    'message': 'Certificate link successfully sent'
                }
            }, status=status.HTTP_200_OK)
            
            
        else:
            return Response({
                'status': 'failure',
                'data': { 'message': 'Incorrect request format.', 'errors': serializer.errors}
            }, status=status.HTTP_400_BAD_REQUEST)