python 发邮件的功能
1 import smtplib 2 from email.mime.text import MIMEText 3 from email.utils import formataddr 4 5 #发送邮件功能 6 def send_mail(send_message_txt,*senders_list,**send_to_people): 7 flag = True 8 try: 9 #编写发送的内容 10 send_msg = MIMEText(send_message_txt,"plain","utf-8") 11 send_msg["From"] = formataddr(["发送人姓名","邮箱账号"]) 12 #f发送人的名单 13 for sender_name,mail_address in send_to_people.items(): 14 send_msg["To"] = formataddr([sender_name,mail_address]) 15 else: 16 print("添加所有发送人") 17 send_msg["Subject"] = "出现异常的sqlmap文件内容" 18 #登录邮箱服务器 19 send_server = smtplib.SMTP("smtp.126.com",25) 20 send_server.login("登录邮箱账号","邮箱密码") 21 #发送邮件 22 send_server.sendmail("xxx@126.com",senders_list,send_msg.as_string()) 23 send_server.quit() 24 except Exception as e: 25 print(e) 26 flag = False 27 return flag