Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Send email in Django now that Google changed the policy . WinError 10061] No connection could be made because the target machine actively refused it

Ask Question

I'm working on a Django project. I need to send my users the emails and receive the contact us form when users submit the form. I'm using Gmail. As I watched tutorials, the email which receives the emails need to turn on less secure on security section. However, as May 2022 google changed the policy and now the option is not there.

https://support.google.com/accounts/answer/6010255?authuser=1&hl=en&authuser=1&visit_id=638033119094066220-3031639860&p=less-secure-apps&rd=1

So, now when I'm trying to send an email I face the following error.

ConnectionRefusedError at /contact/
[WinError 10061] No connection could be made because the target machine actively refused it
Request Method: POST
Request URL:    http://127.0.0.1:8000/contact/
Django Version: 4.1.2
Exception Type: ConnectionRefusedError
Exception Value:    
[WinError 10061] No connection could be made because the target machine actively refused it
Exception Location: C:\Users\Sed AKH\AppData\Local\Programs\Python\Python38\lib\socket.py, line 796, in create_connection
Raised during:  main.views.contact
Python Executable:  C:\Users\Sed AKH\AppData\Local\Programs\Python\Python38\python.exe
Python Version: 3.8.1
Python Path:    
['E:\\Projects\\Python\\Django\\weblimey',
 'C:\\Users\\Sed AKH\\AppData\\Local\\Programs\\Python\\Python38\\python38.zip',
 'C:\\Users\\Sed AKH\\AppData\\Local\\Programs\\Python\\Python38\\DLLs',
 'C:\\Users\\Sed AKH\\AppData\\Local\\Programs\\Python\\Python38\\lib',
 'C:\\Users\\Sed AKH\\AppData\\Local\\Programs\\Python\\Python38',
 'C:\\Users\\Sed '
 'AKH\\AppData\\Local\\Programs\\Python\\Python38\\lib\\site-packages',
 'C:\\Users\\Sed '
 'AKH\\AppData\\Local\\Programs\\Python\\Python38\\lib\\site-packages\\win32',
 'C:\\Users\\Sed '
 'AKH\\AppData\\Local\\Programs\\Python\\Python38\\lib\\site-packages\\win32\\lib',
 'C:\\Users\\Sed '
 'AKH\\AppData\\Local\\Programs\\Python\\Python38\\lib\\site-packages\\Pythonwin']
Server time:    Sun, 06 Nov 2022 06:26:20 +0000

And here my code :

def contact(request):
    if request.method == 'POST':
            contact = ContactForm()
            name = request.POST.get('name')
            email = request.POST.get('email')
            message = request.POST.get('message')
            contact.name = name
            contact.email = email
            contact.message = message
            contact.save()
        except Exception  as ve:
            print('Something happend')
        finally:
            send_mail(name,message,email,['sportold4@gmail.com'],fail_silently=False)
            return render(request, 'contact.html',{'page': 'contact'})
    return render(request, 'contact.html',{'page': 'contact'})

Can Anyone tell me what's the cause and if there is any another way to send email in Django?

Does this answer your question? No connection could be made because the target machine actively refused it (Django) – Sunderam Dubey Nov 6, 2022 at 6:47 Thanks for your understand. Can you please upvote the question so other get encourage to answer the question. – Abdu4 Nov 6, 2022 at 6:56

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.