python#模拟发送电子邮件

 1 #-*- coding:utf-8 -*-
 2 #模拟发送电子邮件
 3 from email.mime.text import MIMEText
 4 
 5 
 6 from_addr = 'aa@sss.com'
 7 password = input('Passord:')
 8 to_addr = 'test8@qq.com'
 9 
10 smtp_server = 'mail.lingrui.com'
11 
12 context = ' 为此次峰会互动提供了礼品支持,冬'
13 
14 msg = MIMEText(context,'plain','utf-8')
15 msg['Subject']='Python send mail'
16 msg['From'] = from_addr
17 
18 import smtplib
19 
20 server = smtplib.SMTP(smtp_server,25)
21 server.set_debuglevel(1)
22 server.login(from_addr,password)
23 server.sendmail(from_addr,[to_addr],msg.as_string())
24 server.quit()
25 
26 print('邮件发送至 %s 成功' %to_addr)
原文地址:https://www.cnblogs.com/lrzy/p/5555071.html