Search code examples
pythonpython-3.xsmtp

Getting error: SMTP AUTH extension not supported by server Python3


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 = "myEmail@gmail.com"
        #pwd = No need for password with this SMTP
        subject = "Test subject"
        recipients = "some_recipientk@blabla.com"
        #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")

Solution

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

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