Search code examples
djangosmtpgmailapache2linode

Unable to connect to gmail smtp linode django apache2 setup


Hello im having difficulties connecting to google smtp server. The context is that whenever a user fills in a form , my program will automatically email me the feedback to my gmail account. Everything is working except for the fact that the program is stuck within the send_mail function.

I have tried doing this :

telnet smtp.gmail.com 25
Trying 2404:6800:4003:c03::6c...

Which will eventually result in a time out.

Here is some of my code:

settings.py

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'xxxxxx'
EMAIL_PORT = 465
EMAIL_USE_TLS = False
EMAIL_USE_SSL = True                                                                                                                  
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER                                                                                                  
SERVER_EMAIL = DEFAULT_FROM_EMAIL     

As per out of the box from wagtail(django cms package)

I thought it might have to do with my UFW blocking it , however i have tried disabling the UFW and restarting apache2 . This unfortunately does not help.

ufw status

Status: active

To                         Action      From
--                         ------      ----
22/tcp                     ALLOW       Anywhere
80/tcp                     ALLOW       Anywhere
443/tcp                    ALLOW       Anywhere
22/tcp (v6)                ALLOW       Anywhere (v6)
80/tcp (v6)                ALLOW       Anywhere (v6)
443/tcp (v6)               ALLOW       Anywhere (v6)

I am really lost! Please help . Thanks


Solution

  • Newly created Linode accounts restrict the use of mailing ports (25, 465, and 587) by default.

    In an effort to fight spam, new Linode accounts created after Tuesday, 5 November, 2019 have mailing ports (25, 465, and 587) restricted by default (see our blog post here for more information).

    However, If you would like to use your Linodes for sending emails, you will first need to configure :

    1. a valid DNS A record and
    2. rDNS for any Linodes that you plan to use to send emails.

    You can see how to do that here: [source]