question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SMTP AUTH extension not supported by server.

See original GitHub issue

hello, i’am using aiosmtpd as a server proxy mail, i want analyze traffic mail, it’s normal if i’m not use Authentication, i can send a mail. but if i use authenticator on Controller my client side give me an error “SMTP AUTH extension not supported by server.”

i try example of aiosmtpd/examples/authenticated_relayer/server.py , but same result.

python version : 3.6 OS : MacOS BigSur 11.5.2 , i try running on docker with base ubuntu 20.04, same result on me

Server Code :

    class Authenticator:
        def __init__(self, auth_database):
            self.auth_db = Path(auth_database)

        def __call__(self, server, session, envelope, mechanism, auth_data):
            fail_nothandled = AuthResult(success=False, handled=False)
            if mechanism not in ("LOGIN", "PLAIN"):
                return fail_nothandled
            if not isinstance(auth_data, LoginPassword):
                return fail_nothandled
            username = auth_data.login
            password = auth_data.password
            hashpass = password
            conn = sqlite3.connect(self.auth_db)
            curs = conn.execute(
                "SELECT hashpass FROM userauth WHERE username=?", (username,)
            )
            hash_db = curs.fetchone()
            conn.close()
            if not hash_db:
                return fail_nothandled
            if hashpass != hash_db[0]:
                return fail_nothandled
            return AuthResult(success=True)


    logging.basicConfig(level=logging.DEBUG)
    controller = Controller(
        MailProxyHandler(
            host=config.get('remote', 'host'),
            port=config.getint('remote', 'port', fallback=25),
            auth=remote_auth,
            use_ssl=config.getboolean('remote', 'use_ssl', fallback=False),
            starttls=config.getboolean('remote', 'starttls', fallback=False),
        ),
        hostname=config.get('local', 'host', fallback='127.0.0.1'),
        port=config.getint('local', 'port', fallback=25),
        authenticator=Authenticator(DB_AUTH),
        auth_required=True
    )
    controller.start()

    print("Mail proxy started ...")
    print("Remote Server : " + config.get('remote', 'host'))
    while controller.loop.is_running():
        sleep(0.2)

Client Code :

port = 8465  
smtp_server = "127.0.0.1"
sender_email = "lalala@gmail.com"  # Enter your address
to = "FF <lalala@gmail.com>"  # Enter receiver address
cc = ["lalala@lalala.co.id", "YOYO HE <lalala@lalala.co.id>"]
bcc = "lalala@gmail.com"

text = "Hi!\nHow are you?\nHere is the link you wanted:\nhttp://www.python.org"
html = """\
<html>
  <head></head>
  <body>
    <p>Hi!<br>
       How are you?<br>
       Here is the <a href="http://www.python.org">link</a> you wanted.
    </p>
  </body>
</html>
"""

part1 = MIMEText(text, 'plain')
part2 = MIMEText(html, 'html')

msg = MIMEMultipart()
msg['Subject'] = "This is subject"
msg['From'] = 'hehehe@gmail.com'
msg['To'] = to
msg['Cc'] = ", ".join(cc)

msg.attach(part1)
msg.attach(part2)

rcpt = [to]
with smtplib.SMTP(smtp_server, port) as server:
    server.connect(smtp_server, port)
    server.set_debuglevel(1)
    server.login("user1", "password1")
    server.sendmail(sender_email, rcpt, msg.as_string())

Server LOG : Screen Shot 2021-09-14 at 16 43 13

Client LOG : Screen Shot 2021-09-14 at 16 43 27

Thank you for your help

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:11

github_iconTop GitHub Comments

1reaction
cbrandcommented, Oct 28, 2021

I ran into this too when I tried to connect to an SMTP server and I think I found the root cause.

The issue / missing link is in the implementation of the ehlo handler: https://github.com/aio-libs/aiosmtpd/blob/master/aiosmtpd/smtp.py#L833

Here the AUTH extension is only sent if there exists a valid TLS connection. This makes sense, especially on publicly hosted services. Further checks have seen that the TLS check only works if a connection is established via STARTTLS.

Without this no authentication support as documented in the docs is possible.

Knowing this, and explicitly initiating a connection with STARTTLS seems to work:

import smtplib, ssl

user = "test"
password = "secretpw"

# Create a secure SSL context
context = ssl.create_default_context()


sender_email = "test@example.com"
receiver_email = "receiver@example.com"
message = """\
From: test@example.com
To: receiver@example.com
Subject: Hi there

This message is sent from Python."""

with smtplib.SMTP("smtp.example.com", 568) as server:
    server.helo()
    server.ehlo()
    server.starttls(context=context)
    server.login(user, password)
    server.sendmail(sender_email, receiver_email, message)

It doesn’t seem to work for TLS connections which are not initiated with STARTTLS though if I read the code correctly.

1reaction
febriyan1302commented, Oct 7, 2021

hallo @zcy382725 @l86610273

after understanding the aiosmtpd library and following this code , i solve my problem.

so, i don’t need authentication , what we need is handle_AUTH

Correct me if i am wrong

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - SMTP AUTH extension not supported by server
In my case, uncommenting the lines EMAIL_HOST_USER and EMAIL_HOST_PASSWORD and setting both variables to an empty string was enough. I'm using Taiga6 with...
Read more >
SMTP auth extension not supported by the server - Courier
This error occurs when you connect to the SMTP server using an invalid port, protocol (SSL or TLS), or if your sender account...
Read more >
SMTP AUTH extension not supported by server
Hi there, i tried to use gmail's smtp server for the dev_appserver but it does not work. POP3 is activated and the dev_appserver...
Read more >
SMTP AUTH extension not supported by server : Forums
Well, it could be that the server you are trying to send smtp mail from actually doesn't support auth. Alternatively, this is some...
Read more >
SMTP AUTH extension not supported by server
bnj je suis bloqué depuis deux jours sur un problÚme d'envoie d'un mail avec django enfaite j'ai tous fait a l'aide de documentation...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found