首页 > 代码库 > smtp模块使用
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‘] = "christmas_alerts@pythonscraping.com" 11 msg[‘To‘] = "ryan@pythonscraping.com" 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模块使用
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。