python3.4+pyqt4邮件关机

python3.4+pyqt4邮件关机,第1张

概述python3.4+pyqt4邮件关机

下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。

内存溢出小编现在分享给大家,也给大家做个参考。

# -*- Coding: utf-8 -*-"""Module implementing Dialog."""import pickleimport smtplib  import email.mime.multipart  import email.mime.text  import os,sys,string,emailimport poplibimport winsoundimport time#from PyQt4.QtCore import pyqtSlot,QMessageBox#from PyQt4.QtGui import QDialogfrom PyQt4.QtGui import *from PyQt4.QtCore import *from Ui_shutdown import Ui_Dialogclass Dialog(QDialog,Ui_Dialog):    """    Class documentation goes here.    """    def __init__(self,parent=None):        """        Constructor                @param parent reference to the parent Widget (QWidget)        """        super().__init__(parent)        self.setupUi(self)                        self.email=''        self.password=''        self.reemail=''        self.user={}         self.subject={}        self.load_data()        self.lineEmail.setText(self.user['email'])        self.linePw.setText(self.user['password'])        self.lineReEmail.setText(self.user['reemail'])    @pyqtSlot()    def on_pushbuttonOK_clicked(self):        """        Slot documentation goes here.        """        # Todo: not implemented yet        #pass        #raise NotImplementedError        self.email=self.lineEmail.text()        self.password=self.linePw.text()        self.reemail=self.lineReEmail.text()        self.save_data()        winsound.PlaySound('OK',winsound.MB_OK)        QMessageBox.information(self,"OK",'设置成功!')        #self.shutdowndown()        while True:            self.shutdowndown()            time.sleep(60)                         def save_data(self):         '''''        try:            os.remove( 'user.pickle' )        except  windowsError:            pass            '''        self.user['email']=self.email         self.user['password']=self.password          self.user['reemail']=self.reemail          #with保证自动关闭文件          #设置文件模式为'wb'来以二进制写模式打开文件          with open('user.pickle','wb') as f:              #dump()函数接受一个可序列化的Python数据结构              pickle.dump(self.user,f)      def load_data(self):        with open('user.pickle','rb') as f:              self.user=pickle.load(f)              #user变量是一个字典           def accept_mail(self):        self.load_data()        host = "pop.163.com"        username = self.user['email']        password = self.user['password']        pp = poplib.POP3_SSL(host)        pp.user(username)        pp.pass_(password)        ret=pp.stat()        mailnum=ret[0]        hdr,message,octet = pp.retr(mailnum)        mail=email.message_from_bytes('\n'.encode('utf-8').join(message))        self.subject = email.header.decode_header(mail.get('subject'))        if self.subject[0][0] == 'shutdown':            pp.dele(mailnum)        pp.quit()        #print(subject[0][0])        #print(subject[0][0] == 'test')    def shutdowndown(self):        self.accept_mail()        if self.subject[0][0] == 'shutdown':            self.send_mail()            cmd="cmd.exe /k shutdown -s -t 0"            os.system(cmd)            pass    def send_mail(self):        msg=email.mime.multipart.MIMEMultipart()          msg['from']=self.user['email']         msg['to']=self.user['reemail']         msg['subject']='Done!!!'          content='''''              主人,             您的电脑已成功关机!                                        '''          txt=email.mime.text.MIMEText(content)          msg.attach(txt)          smtp=smtplib          smtp=smtplib.SMTP()          smtp.connect('smtp.163.com','25')        smtp.login(self.user['email'],self.user['password'])        smtp.sendmail(self.user['email'],self.user['reemail'],str(msg))          smtp.quit()             #if __name__ == '__main__':     # import sysfrom PyQt4 import QtGui    app = QtGui.QApplication(sys.argv)dlg = Dialog()dlg.show()sys.exit(app.exec_())

以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

总结

以上是内存溢出为你收集整理的python3.4+pyqt4邮件关机全部内容,希望文章能够帮你解决python3.4+pyqt4邮件关机所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1199031.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-04
下一篇 2022-06-04

发表评论

登录后才能评论

评论列表(0条)

保存