aditya k.
aditya k.

Reputation: 35

TimeoutError when trying to send email in django

enter image description here

   Hello i am getting TimeoutError while trying to send mail through django .

the error shows as: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

          def mail_send_view(request, id):
          subject = 'Subject'
          message = 'message'
          send_mail(subject, message,  '[email protected]', 
                                                    ['[email protected]'],fail_silently=False)

          return render(request, 'blog/sharebymail.html', {'form': form, 'post': post, 'sent': sent})

Upvotes: 1

Views: 1752

Answers (1)

sebastienbarbier
sebastienbarbier

Reputation: 6832

That is more than likely coming from an issue with your email provider. Does your code works on your machine using the email/#console-backend ?

On settings.py, set EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' and try sending an email using your code. If the email display on console, it's an issue with your provider, and so your hosting platform.

Most hosting platform do not provide a default smtp value, you then need to find one and setup your env properly using smtp-backend:


    host: EMAIL_HOST
    port: EMAIL_PORT
    username: EMAIL_HOST_USER
    password: EMAIL_HOST_PASSWORD
    use_tls: EMAIL_USE_TLS
    use_ssl: EMAIL_USE_SSL
    timeout: EMAIL_TIMEOUT
    ssl_keyfile: EMAIL_SSL_KEYFILE
    ssl_certfile: EMAIL_SSL_CERTFILE

Upvotes: 1

Related Questions