EmailMessage issues timeout

Submitted 3 years, 7 months ago
Ticket #100
Views 307
Language/Framework Django
Priority High
Status Closed

I have just uploaded my django project to a ubuntu server at Linode.com. I wanted to test out my site by running a development server via the ubuntu server at linode. I can access the website just fine from the development server. My problem is that i have a contact form at the bottom of my website. The contact form is made within HTML, and then i am accessing the different inputs from my views.py file. It all worked just as fine when i started a development server on my localmachine (My PC). Now that i have uploaded the django-project i can no longer use the contact form, and it gives me a timeout error, when i am submitting the message.

I have tried to search on the internet on how i can possibly fix the problem but i cant seem to find the solution so i am hoping that i can get some help from here.

My mail server is at PrivateEmail.com, which i bought through NameCheap.

Link to my errors(image) https://i.stack.imgur.com/51ETk.png

Here is how i am sending the email message

def index(request):

if request.method == 'POST':
    contacters_name = request.POST['contacters_name']
    contacters_subject = request.POST['contacters_subject']
    contacters_message = request.POST['contacters_message']
    contacters_email = request.POST['contacters_email']

    email = EmailMessage(
        contacters_subject + '| Message from ' + contacters_name + ' - ' + contacters_email,
        contacters_message,
        'mail@lassejonassen.com',
        ['mail@lassejonassen.com'],
    )
    email.send()
    return redirect('/')

return render(request, 'base/index.html')

Here is the html form

<form method="post">
    {% csrf_token %}
    <p>Your name</p>
    <input name="contacters_name" type="text"required>
    <p>Your email</p>
    <input name="contacters_email"  type="email"required>
    <p>Subject</p>
    <input name="contacters_subject" type="text"required>
    <p>Your message</p>
    <textarea name="contacters_message" required></textarea>
    <button type="submit">Send Message</button>
</form>

Here is my settings.py email settings

   #Email Settings - PrivateEmail
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
DEFAULT_FROM_EMAIL = 'mail@mydomain.com'
SERVER_EMAIL = 'mail@mydomain.com'
EMAIL_USE_SSL = True
EMAIL_HOST = 'mail.privateemail.com'
EMAIL_HOST_USER = 'mail@mydomain.com'
EMAIL_HOST_PASSWORD  = 'Pass-to-my-email'
EMAIL_PORT = 465
Submitted on Aug 07, 20
add a comment

1 Answer

Verified

@ Lassejonassen Did you try send mail using Django Shell?.If not can you quickly check and let me know  the error you get in Django shell?

Also make sure EMAIL_PORT is correct because sometime PORT issue leads to CONNECTION timeout.

Also try add  use_tls=True ,

Below are the reference from Django documentation,

EMAIL_USE_TLS

Default: False

Whether to use a TLS (secure) connection when talking to the SMTP server. This is used for explicit TLS connections, generally on port 587. If you are experiencing hanging connections, see the implicit TLS setting EMAIL_USE_SSL.

Submitted 3 years, 7 months ago

I have tried to switch to using the SMTPLib module. And it works on my local machine once again. But when i start the development server on my ubuntu server, i get the same error. A timeout.

I am wondering if i get the error because i am using a development server on the production server?

- lassejonassen 3 years, 7 months ago

are you running your domain/server with SSL?. can you try with change DEBUG=False?

- scott 3 years, 7 months ago

may be check this i got these from SO
'Connection timed out' means Django couldn't connect to your email server. Type this on a command line:

telnet smtp.xxxx.com.kh 25 You should get a response from the email server, something like:

220 rufus Python SMTP proxy version 0.2 If you don't get a response,you have found the problem.

Here's a handy command to run a local development server, on Linux:

sudo /usr/lib/python2.6/smtpd.py -n -c DebuggingServer 127.0.0.1:25

- scott 3 years, 7 months ago

I have gotten the emailing to work.

It turns out that the supporters from my host, Linode.com, have to turn off some restrictions that they automatically have set on new accounts.

- lassejonassen 3 years, 7 months ago

Excellent. Finally you resolved the issue. Happy coding :). Also if you are interested you can participate in helping other developers here :)

- scott 3 years, 7 months ago

I will of course keep on looking on the community to look out for people who have a problem that i can possibly solve, even though i am not as experienced yet :)

- lassejonassen 3 years, 7 months ago

Thanks @scott for you support. @Lassejonassen , if the issue has been resolved, could you close the ticket from your end?

- Vengat 3 years, 7 months ago

@Aruntck I will do that :)

- lassejonassen 3 years, 7 months ago


Wanna Post Ad?
Reach a large group of audience by posting an ad about your business here. For more details
Drop us a Message

Latest Blogs