smtp模块使用
Posted Braveliberty
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了smtp模块使用相关的知识,希望对你有一定的参考价值。
1 import smtplib 2 from email.mime.text import MIMEText 3 from bs4 import BeautifulSoup 4 from urllib.request import urlopen 5 import time 6 7 def sendMail(subject, body): 8 msg = MIMEText(body) 9 msg[‘Subject‘] = subject 10 msg[‘From‘] = "[email protected]" 11 msg[‘To‘] = "[email protected]" 12 13 s = smtplib.SMTP(‘localhost‘) 14 s.send_message(msg) 15 s.quit() 16 17 bsObj = BeautifulSoup(urlopen("https://isitchristmas.com/")) 18 while(bsObj.find("a", {"id":"answer"}).attrs[‘title‘] == "NO"): 19 print("It is not Christmas yet.") 20 time.sleep(3600) 21 bsObj = BeautifulSoup(urlopen("https://isitchristmas.com/")) 22 sendMail("It‘s Christmas!", "According to http://itischristmas.com, it is Christmas!")
利用smtplib来检测网站的变化,然后给自己发邮件
以上是关于smtp模块使用的主要内容,如果未能解决你的问题,请参考以下文章