📅  最后修改于: 2023-12-03 14:58:16.363000             🧑  作者: Mango
该错误通常出现在使用SMTP(简单邮件传输协议)发送电子邮件时,表示缺少PLAIN身份验证的凭据。
import smtplib
from email.mime.text import MIMEText
# 构造消息
msg = MIMEText('Hello, World!')
msg['Subject'] = 'Test email'
msg['From'] = 'your_email@example.com'
msg['To'] = 'recipient_email@example.com'
# 连接到SMTP服务器
smtp_server = 'smtp.example.com'
smtp_port = 587
smtp_username = 'your_email@example.com'
smtp_password = 'your_email_password'
try:
smtpobj = smtplib.SMTP(smtp_server, smtp_port)
smtpobj.starttls()
smtpobj.login(smtp_username, smtp_password)
smtpobj.sendmail(smtp_username, [msg['To']], msg.as_string())
smtpobj.quit()
print('Email sent successfully.')
except smtplib.SMTPException as e:
print('Error: %s' % e)
在发送邮件时,注意将 smtp_username
和 smtp_password
更改为正确的凭据。如果仍然遇到错误:缺少“PLAIN”的凭据
,请参照上述解决方法解决问题。