26 ptyhon发送邮件模块
1 # coding=utf-8 2 import smtplib 3 from email.mime.text import MIMEText ##标准邮件格式 4 print ("xxxxx") 5 mail_list=["344472947@qq.com"] ## 定义收件人列表 6 mail_host="smtp.163.com"##发件邮箱的服务器 7 mail_username="17717033590@163.com" ##定义发件邮件的帐号 8 mail_password="19870405a" ##密码 9 10 def send_mail(text,to_mail): 11 my="huangyuanyuan"+"<"+mail_username+">" 12 msg=MIMEText(text,_subtype="html",_charset="utf-8") 13 msg['To']=':'.join(to_mail) 14 msg['from']=my 15 msg['subject']="同学们好" 16 try: 17 s=smtplib.SMTP()#实例化对象 18 s.connect(mail_host) ##连接发送服务器 19 s.login(mail_username,mail_password)##登录发送邮箱的帐号和密码 20 s.sendmail(my,to_mail,msg.as_string()) ##发送邮件 21 s.close() 22 print ('进程正常发送') 23 except Exception: 24 print ('发生异常') 25 26 27 text='<a href="https://www.baidu.com">这里有python课程哦</a>' 28 send_mail(text,mail_list)