Hi there,
Its been days and I am stuck.
Whenever I try to send email, I get “502 Bad Gateway” error.
Configuration:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'golf.mywebsitebox.com' 
EMAIL_HOST_USER = '' 
EMAIL_HOST_PASSWORD = ''
EMAIL_PORT = 465
EMAIL_USE_TLS = True

I am using Ubunto OS with Nginx and Gunicorn. I have opened ticket twice with this issue but no one is responding.
Hope someone here responds.

edited by bobbyiliev

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

Hi there @mahawaqar9875,

There are a few things that you need to consider:

  • If you are using a firewall on your Droplet like UFW, make sure to allow the outgoing TCP traffic for port 465

  • If you are using a Cloud Firewall, make sure to allow the outgoing TCP traffic for port 465 as well

  • Once you have opened port 465, test this is actually the case by running the following command from your Droplet:

  • telnet portquiz.net 465
  • If you have port 465 open already try running telnet from your Droplet to your mail server:
  • telnet golf.mywebsitebox.com 465
  • Make sure that your Droplet’s IP address is not blocked by the firewall on your mail server

Let me know how it goes!
Regards,
Bobby

  • Hi Bobby,

    Thanks for quick response. Following your instructions, when I run

    telnet portquiz.net 465
    

    I got this :

    Trying 52.47.209.216...
    Connected to portquiz.net.
    Escape character is '^]'.
    
    

    but when I run telnet golf.mywebsitebox.com 465, I get this:

    Trying 46.4.227.96...
    telnet: Unable to connect to remote host: Connection timed out
    
    

    Now what should be my next step?
    I’ll be very thankful if you sort’ll this out.

    • Hi there @mahawaqar9875,

      It looks like that port 465 is open on your Droplet.

      This means that you would need to allow your Droplet’s IP address via your golf.mywebsitebox.com mail server firewall.

      Let me know how it goes!
      Regards,
      Bobby

      • Hi Bobby,
        Somehow my mail service provider answered me this:
        “It is SMTP service and SMTP is not restricted to certain IPs. So adding an IP is not required”.

        They asked me to change 465 port to 26, I also did that but nothing worked out.

        • Hi there @mahawaqar9875,

          I tested this at my end and I actually do not get a response back on port 465 from Exim, but if I try to connect on port 26 it seems to work as expected:

          # telnet golf.mywebsitebox.com 26
          
          Trying 46.4.227.96...
          Connected to 46.4.227.96.
          Escape character is '^]'.
          220-golf.mywebsitebox.com ESMTP Exim 4.92 #2 Wed, 27 May 2020 12:15:11 +0500
          220-We do not authorize the use of this system to transport unsolicited,
          220 and/or bulk e-mail.
          

          Can you try running the two telnet commands on port 26 and see if they both work?

          Regards,
          Bobby

          • Hi Bobby,

            Something is weird.
            My laptop basically has Window OS. When I run telnet command from window OS for port 26, it gets connected.
            But my droplet is on Ubuntu OS. When I run

            telnet golf.mywebsitebox.com 26
            

            from server, it don’t gets connected. Is there is something to do over here to get it connected from Ubunto too?

          • Hi there @mahawaqar9875,

            It sounds like either your Droplet has port 26 closed or that you have a Cloud Firewall enabled.

            If you have UFW enabled, can you share the output of the following command:

            • sudo ufw status

            The other logical explanation is that the mail server is blocking your IP but they’ve already confirmed that this is not the case.

            What is the location of your Droplet? I would try to spin up a Droplet in the same location and run a quick telnet test.

            Another suggestion that I could give here is to get in touch with DigitalOcean and cross check with them as well if anything could be blocking the traffic to your mail server.

            Let me know how it goes!
            Regards,
            Bobby

Submit an Answer