How to fix django timeout error when sending email

106 Views Asked by At

I'm trying to make a simple django app that sends an email to a user, but every time i try to run the program, i get an error 'TimeoutError at /automail2/success [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond'

this happens after a couple seconds of loading after the email address has been submitted. Here's a github link to the code

https://github.com/Taterbro/automail

I'm fairly new to coding and the stackoverflow community, so any help would be appreciated.

tried to send an email using django expected the code to send an email the code timed out while trying to send the email

1

There are 1 best solutions below

0
raphael On

Fix the timeout error

As I noted in the comments,your timeout error was caused because the HTML template was using the wrong string for the action. You can't use the name of the url path as the action, you need to have Django generate it when it renders the page:

<!-- index.html -->

<!-- change -->
<form action='success' method="post">

<!-- to -->
<form action='{% url "success" %}' method="post">

Fix the connection refused error

Here the problem is not with your views.py code or your template, rather with the settings you use in settings.py and the way you have your email set up.

I have tried your code, and it works fine, but you need to change your gmail settings, and use those settings for your settings.py. As stated in this answer, you have to generate an app password if you want to use gmail to send emails in Django. Here is a tutorial on how to do that.

How to post a question on Stack Overflow

To answer your other comment question, you should post code, not images of code, or in your case a GitHub link. Here is a link that explains why and also explains how to post code. In your specific case it would be helpful if your edit your question to include the relevant views.py, urls.py, settings.py and the index.html template files.