STARTTLS extension not supported by server

Viewed 56805

This maybe a repeated question but I'm still facing issues on this, hope there's a solution around. Thanks in advance.

I'm trying to send mail through the company's server

I'm currently using Python version 2.6 and Ubuntu 10.04

This is the error message I got

Traceback (most recent call last):

  File "hxmass-mail-edit.py", line 227, in <module>
    server.starttls()

  File "/usr/lib/python2.6/smtplib.py", line 611, in starttls
    raise SMTPException("STARTTLS extension not supported by server.") smtplib.SMTPException: STARTTLS extension not supported by server.

Here goes part of the code

server = smtplib.SMTP('smtp.abc.com', 587)
server.set_debuglevel(1)
server.ehlo()
server.starttls()
server.ehlo()
server.login('sales@abc.com', 'abc123')
addressbook=sys.argv[1]
9 Answers

I had a similar issue trying to send a mail through the company's server (without autentication needed)

I solved removing the server.ehlo and removing the port number:

server = smtplib.SMTP("smtp.mycompany.com")
server.sendmail(fromaddr, toaddr, text)
from smtplib import SMTP_SSL, SMTP, SMTPAuthenticationError
from ssl import create_default_context
from email.message import EmailMessage

sender = 'aaa@bbb.com'
description = "This is the test description supposed to be in body of the email."
msg = EmailMessage()
msg.set_content(description)
msg['Subject'] = 'This is a test title'
msg['From'] = f"Python SMTP <{sender}>"
msg['To'] = 'bbb@ccc.com'


def using_ssl():
    try:
        server = SMTP_SSL(host='smtp.gmail.com', port=465, context=create_default_context())
        server.login(sender, password)
        server.send_message(msg=msg)
        server.quit()
        server.close()
    except SMTPAuthenticationError:
        print('Login Failed')


def using_tls():
    try:
        server = SMTP(host='smtp.gmail.com', port=587)
        server.starttls(context=create_default_context())
        server.ehlo()
        server.login(sender, password)
        server.send_message(msg=msg)
        server.quit()
        server.close()
    except SMTPAuthenticationError:
        print('Login Failed')

By testing and researching myself, I found out that the gmail servers do not use tls connections with python anymore.

You must not use service.startttls(). Gmail service do not support this type of connection anymore.

Also remember to use the SMTP ports (mail reserved ports) for sending emails. POP3 and IMAP ports for receiving email.


        s_u = "Test"

        service = smtplib.SMTP_SSL("smtp.gmail.com", 465)

        service.ehlo()

        service.sendmail("SENDER_EMAIL","RECEIVER_EMAIL","MESSAGE")

        

I you can't send the email even if you put the correct credentials, look at this: Login credentials not working with Gmail SMTP

Related