STARTTLS extension not supported by server - Getting this error when trying to send an email through Django and a private email address
Asked Answered
P

5

12

I registered a domain and a private email using namecheap.com. I am trying to send an email from this private email. However, I get the error in the title.

In my settings.py, I have these settings:

EMAIL_HOST = 'mail.privateemail.com'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'my password'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER

And I am trying to send the email through a view:

send_mail(
    'Subject here',
    'Here is the message.',
    '[email protected]',
    ['[email protected]'],
    fail_silently=False,
)

However, I get this error:

SMTPException at /
STARTTLS extension not supported by server.

Any idea why? Any help is appreciated.

EDIT

After changing the EMAIL_USE_TLS to False, and also removing it to check both separately, I get this error now:

SMTP AUTH extension not supported by server.

Any idea why? Thanks!

Parasite answered 30/6, 2016 at 23:14 Comment(0)
E
15

your server mail.privateemail.com does not know what is STARTTLS SMTP Commnad is

this may happen in two cases:

  1. your server (mail.privateemail.com) do not support secure communication at all and you need to use plain, non-encrypted communication.
  2. you are trying to connect to the port that is already using SSL as the communication, then STARTTLS to upgrade connection to secure make no sense whatsoever.
  3. your server is configured improperly and ignores STARTTLS on submission port (587).

Judging, that you are connecting to port 587 which should provide plain communication - it's either 1 or 3.

If you want this just work, remove EMAIL_USE_TLS = True or set it to False, otherwise - SMTP server configuration should be fixed.

Esplanade answered 1/7, 2016 at 6:58 Comment(8)
Thanks, but this still does not work. Now, I get this error: SMTP AUTH extension not supported by server.Parasite
This is totally different error, meaning that your SMTP server does not support authentication, remove/disable EMAIL_HOST_USER and EMAIL_HOST_PASSWORD options, an then rollup on the floor and cry for your smtp server as it is open for the spammers...Esplanade
Wait what? So you are saying I can't send emails from the private email I just bought? T_T Is there any solution at all then?Parasite
who says not? just looks like everyone can :DEsplanade
Any idea how though?Parasite
if you have open SMTP server - that does not require authentication... then everyone can send email through itEsplanade
So should I just remove the EMAIL_HOST_USER and EMAIL_HOST_PASSWORD?Parasite
@Esplanade 4 years later, I'm rolled up on the floor and laughing at your comment XDReeducate
T
2

You may try SSL instead of TLS by making following changes in settings.py

EMAIL_USE_SSL = True
EMAIL_PORT = 465

hope that helps

Tallie answered 24/8, 2018 at 9:58 Comment(0)
D
1

Either setup TLS on your mail server or use EMAIL_USE_TLS = False.

Diatessaron answered 30/6, 2016 at 23:17 Comment(2)
Thanks, but this still does not work. Now, I get this error: SMTP AUTH extension not supported by server.Parasite
Hi, TerenceLam, did you fix it? me too, always got those errors!!! Do you know the solution now? Thank you in advance.Drome
C
0

I am able to resolve the issue with modifying below line of code, by adding port number with server name:

server = smtplib.SMTP('mail.mycompany.com:587')     
Cherellecheremis answered 16/1, 2017 at 9:41 Comment(0)
P
0

Not sure if you have solved the problem yet. I also recently try the 2-month free private email package from NameCheap. Here is my code and it works for me as of Jan 2018:

import smtplib
from email.message import EmailMessage

fromaddr = '[email protected]'
toaddrs  = "[email protected]"
SMTPServer = 'mail.privateemail.com'
port = 465 #587
login = "[email protected]"
password = "password"

msg = EmailMessage()
msgtxt = "http://www.google.com"+"\n\n"+"This is a test."
msg.set_content(msgtxt)
msg['Subject'] = "Test message"
msg['From'] = fromaddr
msg['To'] = toaddrs

server = smtplib.SMTP_SSL(SMTPServer, port) #use smtplib.SMTP() if port is 587
#server.starttls()
server.login(login, password)
server.send_message(msg)
server.quit()

Hope this help!

PS. You can also use port 587, but you have to use smtplib.SMTP() instead of smtplib.SMTP_SSL(), and also have to un-comment the server.starttls() line.

Pendulum answered 3/1, 2018 at 7:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.