Answers for "django rest framework send email"

1

django rest framework send email

Method-1 : override the create() method of ConsultViewSet

def send_email():
    email = EmailMessage(
        'Title',
        (ConsultSerializer.name, ConsultSerializer.email, ConsultSerializer.phone),
        'my-email',
        ['my-receive-email']
    )
    email.attach_file(ConsultSerializer.file)
    email.send()


class ConsultViewSet(viewsets.ModelViewSet):
    queryset = Consult.objects.all()
    serializer_class = ConsultSerializer

    def create(self, request, *args, **kwargs):
        response = super(ConsultViewSet, self).create(request, *args, **kwargs)
        send_email()  # sending mail
        return response
Posted by: Guest on March-23-2021

Code answers related to "django rest framework send email"

Python Answers by Framework

Browse Popular Code Answers by Language