0

I want to send an activation Email

your account is successfully created

This is my views.py

class UserAPIView(generics.GenericAPIView, mixins.ListModelMixin, mixins.CreateModelMixin,
                  mixins.UpdateModelMixin, mixins.RetrieveModelMixin,
                  mixins.DestroyModelMixin):
    permission_classes = [permissions.AllowAny]
    serializer_class = UserSerializer
    queryset = User.objects.all()
    lookup_field = 'id'
    filter_backends = [DjangoFilterBackend, filters.SearchFilter]
    filterset_fields = ['email', 'first_name',
                        'last_name', 'roles', 'id', 'contact', 'profile']
    search_fields = ['email']
    ordering_fields = ['first_name']

    def get(self, request, id=None):

        if id:
            return self.retrieve(request)

        else:
            return self.list(request)
            # return Response("Required Id")

    def post(self, request):
        return self.create(request)

    def put(self, request, id=None):
        return self.update(request, id)

This is settings.py

    STATIC_URL = '/static/'
    EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
    EMAIL_HOST = 'smtp.gmail.com'
    EMAIL_USE_TLS = True
    EMAIL_PORT = 587
    EMAIL_HOST_USER = '#####@gmail.com'
    EMAIL_HOST_PASSWORD = '##########'

Please mention where to add the email thing.

  • So right before the *return* statement create a function `send_email` and implement it somewhere - create **util.py** for example and define `def send_email(` there. – dmitryro Sep 26 '20 at 18:41
  • @dmitryro you are talking about this to add `send_mail( 'Subject here', 'Here is the message.', 'from@example.com', ['to@example.com'], fail_silently=False, )` –  Sep 26 '20 at 18:48
  • Yes, there are numerous examples of how to send email in Python. If you activate an account you probably want to generate the activation token and provide it in your email body. https://stackoverflow.com/questions/6270782/how-to-send-an-email-with-python – dmitryro Sep 26 '20 at 18:52

0 Answers0