Django ConnectionResetError: [Errno 54] Connection reset by peer

I'm trying to setup a project to send email from my local machine(MacOS) using django.

But I see this error

File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/ssl.py", line 1309, in do_handshake
    self._sslobj.do_handshake()
ConnectionResetError: [Errno 54] Connection reset by peer

This is code snippet that I have in my local.

class EmailVerificationView(APIView):
    def post(self, request):
        smtp_server = "smtp-relay.brevo.com"
        smtp_port = 587

        s = smtplib.SMTP_SSL(smtp_server, smtp_port, timeout=10)
        email = request.data.get('email')
        s.ehlo()
        s.login("login@email.com", "****")
        s.sendmail("test", email, 'Subject: verified')

        return Response({'message': 'Email sent successfully'}, status=status.HTTP_200_OK)

I have tried few things as well, but nothing seems working.

Вернуться на верх