1 import smtplib 2 from email.mime.text import MIMEText 3 4 mail_user = "[email protected]" 5 mail_pwd = "password" 6 mailto_list=["[email protected]", "[email protected]"] 7 8 def send_mail(from_address, to_address_list, mail_subject, mail_content): 9 msg = MIMEText(mail_content) 10 msg["Subject"] = mail_subject 11 msg[‘From‘] = from_address 12 msg[‘To‘] = ";".join(to_address_list) 13 14 s = smtplib.SMTP("smtp.qq.com", timeout=30)#连接smtp邮件服务器,端口默认是25 15 #s = smtplib.SMTP_SSL("smtp.qq.com", 465) #连接方法一 16 #s = smtplib.SMTP() #连接方法二 17 #s.connect(mail_host) 18 s.login(from_address, mail_pwd) 19 s.sendmail(from_address, to_address_list, msg.as_string()) 20 #s.quit() 21 s.close() 22 23 send_mail(mail_user, mailto_list, ‘群发主题‘, ‘群发内容‘)
时间: 2024-10-10 23:22:06