python SMTP发邮件
#
from email.mime.text import MIMEText from email.header import Header import smtplib # sender = 'zcayyl@163.com' # 发送人的邮箱 sender = '576951284@qq.com' sender_pass = '' # 发送人的邮箱密码/授权码 host = 'smtp.qq.com' # 开启的163/qq邮箱的smtp recivers = ['zcayyl@163.com','1115230598@qq.com'] # 接受者的邮箱 def mail(): message = MIMEText('s17测试', 'plain', 'utf-8') # 第一个参数为内容(可以''' ..换行/编写网页代码 '''),第二个参数为文本格式/html,第三个为编码 message['From'] = '{}'.format(sender) # 发送者 message['To'] = ','.join(recivers) # 接受者 message['Subject'] = '邮件测试' # 主题 try: smtpobj = smtplib.SMTP_SSL(host, 465) # 启用ssl发信,端口为465 smtpobj.login(sender, sender_pass) # 登录 smtpobj.sendmail(sender, recivers, message.as_string()) print('success') smtpobj.quit() except Exception as e: print(e) # print('error') mail() # emqferldqjgbbbai 调用
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
import smtplib from email.mime.text import MIMEText msg = MIMEText(''' 你好: 我是来自 XX 的小伙子, 现在想求职一份Python的工作! 下面是我的附件简历!''') #文本内容 msg['Subject'] = "python爬虫 3年经验 东北大学" msg['From'] = "zcayyl@163.com" msg['To'] = "576951284@qq.com" s = smtplib.SMTP('smtp.163.com') #SMTP_SSL安全发信,端口为465 SMTP/25 s.login('zcayyl@163.com','13038013920') #账号/密码 s.send_message(msg) print('success') #成功 s.quit()