出现错误:服务器 Python3 不支持 SMTP AUTH 扩展

Ser*_*dia 1 python smtp python-3.x

当我测试下面的代码时server = smtplib.SMTP('smpt.gmail.com:587')它工作正常。

但是当我将 SMTP 服务器更改为server = smtplib.SMTP('10.10.9.9: 25')- 时,它给了我一个错误。此 SMTP 不需要任何密码。

那么我在这里缺少什么?

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")
Run Code Online (Sandbox Code Playgroud)

AnF*_*nFi 5

如果服务器不需要身份验证,则不要使用 SMTP AUTH。

删除以下行:
server.login(user, pwd)