1 import smtplib 2 from email.mime.text import MIMEText 3 msg_from=‘1@qq.com‘ #发送方邮箱 4 passwd=‘bd‘ #填入发送方邮箱的授权码 5 msg_to=‘1@qq.com‘ 6 7 8 subject="python邮件测试" #主题 9 content="这是我使用python smtplib及email模块发送的邮件" 10 msg = MIMEText(content) 11 msg[‘Subject‘] = subject 12 msg[‘From‘] = msg_from 13 msg[‘To‘] = msg_to 14 try: 15 s = smtplib.SMTP_SSL("smtp.qq.com",465) 16 s.login(msg_from, passwd) 17 s.sendmail(msg_from, msg_to, msg.as_string()) 18 print( "发送成功") 19 except: 20 print("发送失败") 21 finally: 22 s.quit()
原文地址:https://www.cnblogs.com/pwn2web/p/10430330.html
时间: 2024-11-06 09:55:08