Getting error: SMTP AUTH extension not supported by server Python3

Question:

when I test below code with server = smtplib.SMTP('smpt.gmail.com:587') it works fine.

But when I change SMTP server to server = smtplib.SMTP('10.10.9.9: 25') – it gives me an error. This SMTP does not require any password.

So what am I missing here?

import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import pandas as pd

def send_email(user, recipient, subject):
    try:
        d = {'Col1':[1,2], 'Col2':[3,4]}
        df=pd.DataFrame(d)
        df_html = df.to_html()
        dfPart = MIMEText(df_html,'html')

        user = "[email protected]"
        #pwd = No need for password with this SMTP
        subject = "Test subject"
        recipients = "[email protected]"
        #Container
        msg = MIMEMultipart('alternative')
        msg['Subject'] = subject
        msg['From'] = user
        msg['To'] = ",".join(recipients)
        msg.attach(dfPart)

        #server = smtplib.SMTP('smpt.gmail.com:587') #this works
        server = smtplib.SMTP('10.10.9.9: 25') #this doesn't work
        server.starttls()
        server.login(user, pwd)

        server.sendmail(user, recipients, msg.as_string())
        server.close()
        print("Mail sent succesfully!")
    except Exception as e:
        print(str(e))
        print("Failed to send email")
send_email(user,"","Test Subject")
Asked By: Serdia

||

Answers:

IF the server does not require authentication THEN do not use SMTP AUTH.

Remove the following line:
server.login(user, pwd)

Answered By: AnFi

I am not entirely sure why it’s not working but I have got a few things you can check.

server = smtplib.SMTP('10.10.9.9: 25')
you got a space in the ip:port string, try removing it.

  • The ip:port combination seems to be from a private LAN address.
    Try to ping this address to see if you can reach it, If you can’t then talk to the person who handles the machine with given ip in your network.

    If you can ping the ip, then there is a possibility that the SMTP server is not available on the given port, In that case too contact the person responsible for managing the machine with IP: 10.10.9.9

    use given command on terminal
    ping 10.10.9.9

  • Also before login and and sendmail, you should connect to server using connect(), The correct order would be.

server = smtplib.SMTP('10.10.9.9: 25')
server.starttls()
server.connect('10.10.9.9', 465)
server.login(user, pwd)
server.sendmail(user, recipients, msg.as_string())
server.close()

465 is the default port for SMTP server

Answered By: Jha Hitesh
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.