python+SMTP发送邮件测试报告
发邮件需要用到python两个模块,smtplib和email,这俩模块是python自带的,只需import即可使用。smtplib模块主要负责发送邮件,email模块主要负责构造邮件。其中MIMEText()定义邮件正文,Header()定义邮件标题。MIMEMulipart模块构造带附件。 第一种发送html格式邮件: import smtplib from email.mime.text import MIMEText #MIMEText()定义邮件正文 from email.header import Header #Header()定义邮件标题 #发送邮箱服务器 smtpserver = 'smtp.sina.com' #发送邮箱用户/密码(登录邮箱操作) user = "username@sina.com" password = "password" #发送邮箱 sender = "username@sina.com" #接收邮箱 receiver = "8888@qq.com" #发送主题 subject = 'email by python' #编写HTML类型的邮件正文(把HTML代码写进入) msg = MIMEText( '<html><body><a href="">百度一下</a></p></body></html>', 'html', 'utf-8')