Python发送邮件
1 # 邮件发送 2 import smtplib 3 from email.mime.text import MIMEText 4 5 def send_mail(mail_recv_list, subjict, content): # 定义一个发送邮件的函数 6 mail_send_user = "*********@163.com" # 邮箱用户名 7 mail_send_pass = "********" # 邮箱授权码 8 msg = MIMEText(content,_charset='utf-8') # 邮件的内容 9 msg['Subject'] = subjict # 邮件的主题 10 msg['From'] = mail_send_user # 邮件发送者邮箱 11 msg['To'] = mail_recv_list # 邮件接受者邮箱 12 try: 13 s = smtplib.SMTP_SSL('smtp.163.com') # 链接邮箱服务器 14 s.login(mail_send_user, mail_send_pass) # 使用邮箱名和授权码登录邮箱 15 s.sendmail(mail_send_user, mail_recv_list, msg.as_string()) # 发送邮件 16 s.quit() # 发送完毕退出smtp 17 return True 18 except Exception as e: 19 print(str(e)) # 输出发送失败信息 20 return False 21 22 23 if __name__=="__main__": 24 mail_recv_list = '**********@qq.com' 25 if send_mail(mail_recv_list,'Python发送邮件','测试测试'): 26 print('邮件发送成功') 27 else: