标签:test erro user rom 短信 head 运行 width smt
1. 邮箱服务器:
2. 运行时报错:smtplib.SMTPAuthenticationError: (535, b‘Login Fail. Please enter your authorization code to login.
因为这里要的password是第三方使用邮箱时的password,所以应该是授权码而不是密码
3. 需要在邮箱中进行配置,以QQ邮箱为例:
设置-->账户-->开启SMTP服务
发送短信到指定号码,接收授权码
4. 设置完成,可以写一个简单的发送邮件代码,如下:
1 import smtplib 2 from email.mime.text import MIMEText # MIME(Multipurpose Internet Mail Extensions)多用途互联网邮件扩展类型 3 from email.header import Header 4 5 6 # 发送邮箱服务器 7 smtpserver = ‘smtp.qq.com‘ # QQ邮箱 8 # smtpserver = ‘smtp.163.com‘ # 163邮箱 9 # smtpserver = ‘smtp.mxhichina.com‘ # 钉钉邮箱 10 11 # 发送邮箱用户/密码 12 user = ‘123456789‘ 13 password = ‘fjdkljsf‘ 14 15 # 发送邮箱/接收邮箱 16 sender = ‘123456789@qq.com‘ 17 receiver = ‘123456789@qq.com‘ 18 19 # 发送邮件主题 20 subject = ‘test3333‘ 21 22 # HTML类型的邮件正文 23 msg = MIMEText(‘<html><h1>hello~~~~~~</h1></html>‘, ‘html‘, ‘utf-8‘) 24 msg[‘Subject‘] = Header(subject, ‘utf-8‘) 25 26 # 连接并发送邮件 27 smtp = smtplib.SMTP() 28 smtp.connect(smtpserver) 29 smtp.login(user, password) 30 smtp.sendmail(sender, receiver, msg.as_string()) 31 smtp.quit()
5. OK,收到邮件啦~
标签:test erro user rom 短信 head 运行 width smt
原文地址:https://www.cnblogs.com/xiaochongc/p/12606986.html