1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from email.mime.application import MIMEApplication _user = "sigeken@qq.com" _pwd = "***" _to = "402363522@qq.com"
msg = MIMEMultipart() msg["Subject"] = "don't panic" msg["From"] = _user msg["To"] = _to
part = MIMEText("乔装打扮,不择手段") msg.attach(part)
part = MIMEApplication(open('foo.xlsx','rb').read()) part.add_header('Content-Disposition', 'attachment', filename="foo.xlsx") msg.attach(part)
part = MIMEApplication(open('foo.jpg','rb').read()) part.add_header('Content-Disposition', 'attachment', filename="foo.jpg") msg.attach(part)
part = MIMEApplication(open('foo.pdf','rb').read()) part.add_header('Content-Disposition', 'attachment', filename="foo.pdf") msg.attach(part)
part = MIMEApplication(open('foo.mp3','rb').read()) part.add_header('Content-Disposition', 'attachment', filename="foo.mp3") msg.attach(part) s = smtplib.SMTP("smtp.qq.com", timeout=30) s.login(_user, _pwd) s.sendmail(_user, _to, msg.as_string()) s.close()
|