我正在尝试创建一个单独的记录器,该记录器将通过电子邮件发送错误日志。但是,每次我调用email_logger.error('...')时,都会发生以下错误:
smtplib.SMTPNotSupportedError:服务器不支持SMTP AUTH扩展。
我正在使用的代码在下面显示:
logging.basicConfig(level=logging.INFO, format='%(asctime)s :: %(funcName)s :: %(levelname)s :: %(message)s')
email_logger = logging.getLogger(__name__)
email_logger.setLevel(logging.WARNING)
with smtplib.SMTP('smtp.gmail.com', 587) as server:
server.ehlo()
server.starttls()
server.ehlo()
server.login('[email protected]', r'thisismypassword')
smtp_handler = logging.handlers.SMTPHandler(mailhost=('smtp.gmail.com', 587),
fromaddr='[email protected]',
toaddrs=['[email protected]'],
subject='A dashing subject',
credentials=('[email protected]',
r'thisismypassword'),
secure=None)
formatter = logging.Formatter('%(asctime)s : %(funcName)s : %(levelname)s : %(name)s : %(message)s')
smtp_handler.setFormatter(formatter)
email_logger.addHandler(smtp_handler)
[当我使用Gmail从Python发送电子邮件时,我使用:
server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
此外,请尝试仅在常规python shell中连接到服务器
server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
server.login(username, password)
要查看您的详细信息是否正确,可能需要设置一个应用程序密码才能从应用程序中使用Gmail,具体取决于您的安全设置