11

I am on a Linux machine. My company has an email exchange server which is already configured. I am using a Python script to try to login to the email server so that I can send an email programmatically. Here is what I have so far -

server = smtplib.SMTP('email-0.abc.com', 25)
server.set_debuglevel(1)
server.ehlo_or_helo_if_needed()    
server.login('abc/johndoe', 'pwd')

However, at the server.login command, I get an error as

raise SMTPException("No suitable authentication method found.")
SMTPException: No suitable authentication method found.

Anyone know what the problem is please?

Thanks

4 Answers 4

8

You might need to switch to STARTTLS authentication. Here's an example that helped me.

How To Send Email In Python Via SMTPLIB

Sign up to request clarification or add additional context in comments.

Comments

3

It seems that your Mail Server is rejecting the plain Authentication method.

What server do you use?

If MS Exchange please see this article: http://www.exchangeinbox.com/article.aspx?i=93

1 Comment

Thanks very much, yes I am using MS Exchange, let me check out that article. Meanwhile, I also realised that I can send email without logging in - and that worked. server.sendmail(sender, recipients,msg_txt)
3

The Exchange server I was connecting to, required NTLM authentication, which is not supported by smtplib out of the box.

As of this writing (January 2022) and according to my modest research, the most maintained Python library that solves this problem, is pyspnego. The following snippet was provided by the library author and worked for me without any modifications:

import base64
import spnego

from smtplib import SMTPException, SMTPAuthenticationError


def ntlm_authenticate(smtp, username, password):
    auth = spnego.client(username, password, service="SMTP", protocol="ntlm")
    ntlm_negotiate = auth.step()

    code, response = smtp.docmd("AUTH", "NTLM " + base64.b64encode(ntlm_negotiate).decode())
    if code != 334:
        raise SMTPException("Server did not respond as expected to NTLM negotiate message")

    ntlm_challenge = base64.b64decode(response)
    ntlm_auth = auth.step(ntlm_challenge)
    code, response = smtp.docmd("", base64.b64encode(ntlm_auth).decode())
    if code != 235:
        raise SMTPAuthenticationError(code, response)

1 Comment

I've made username\password values optional and it works... somehow.
0

I was getting the same error. My case could be the different from yours but error is same as you mentioned.

In my scenario, I don't have to pass the username and password for authentication as server IP was added in white-list of SMTP mail server. And I was passing username and password for authentication which was giving me the error stating "No suitable authentication method found."

This may not be the case with you but I just thought to share the my experience for the same kind of error so that anyone coming to this thread can benefit from it.

Thanks.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.