Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 = "[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")
like image 245
Serdia Avatar asked Dec 31 '25 04:12

Serdia


1 Answers

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

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

like image 117
AnFi Avatar answered Jan 02 '26 16:01

AnFi