# coding=utf-8 import smtplib from email.mime.text import MIMEText # 发送纯文本格式的邮件 def sendMail(title, content, mailto_list): msg = MIMEText(content, 'plain', 'utf-8') #发送邮箱地址 sender = 'canarycodebook@163.com' #邮箱授权码,非登陆密码 password = 'HHFLFTMNHUXQTRAE' #收件箱地址 #receiver = '19xxxxxxx9@qq.com' # mailto_list = ['1144131090@qq.com','nayiyewosile@qq.com'] #群发邮箱地址 #smtp服务器 smtp_server = 'smtp.163.com' #发送邮箱地址 msg['From'] = sender #收件箱地址 #msg['To'] = receiver msg['To'] =';'.join(mailto_list) #发送多人邮件写法 #主题 msg['Subject'] = title server = smtplib.SMTP_SSL(smtp_server,465) # SMTP协议默认端口是25 server.login(sender,password) #ogin()方法用来登录SMTP服务器 server.set_debuglevel(1) #打印出和SMTP服务器交互的所有信息。 server.sendmail(sender,mailto_list,msg.as_string()) #msg.as_string()把MIMEText对象变成str server.quit() # 第一个参数为发送者,第二个参数为接收者,可以添加多个例如:['hello@163.com','xxx@qq.com',]# 第三个参数为发送的内容 server.quit()