#encoding=utf-8 __author__ = 'ds' #文件名称冲突 from email.mime.text import MIMEText import smtplib if __name__ == '__main__': msg = MIMEText(_text='SMTP test', _charset='utf-8') #输入Email地址和口令: from_addr = '[email protected]' password = 'XXX' # 输入SMTP服务器地址: smtp_server = 'smtp.qq.com' # 输入收件人地址: to_addr = '[email protected]' #SMTP协议默认端口是25 server = smtplib.SMTP(smtp_server, 25) server.set_debuglevel(1) #server.starttls() #server.connect(host=smtp_server, port=25) #server.esmtp_features["auth"]="AUTH_LOGIN" server.login(from_addr, password) server.sendmail(from_addr, [to_addr], msg.as_string()) server.quit()
测试之后一直报454的错误,原来是QQ邮箱将邮件的SMTP服务关闭了,外部无法访问
打开QQ邮箱账户->账户安全,将SMTP服务和POP3服务打开即可
时间: 2024-10-20 19:43:04