Python enables WeChat to send emails to turn off the computer function, and python to send emails

Source: Internet
Author: User

Python disables the computer for sending mails and python sends mails

Python shuts down the computer by email for your reference. The details are as follows:

Send a QQ email to sina via your mobile phone. Then, use python pop3 to regularly check the mail subject and source of sina's email, and run the corresponding command line on your computer to shut down the email.

Email_test [V1.0]

Import poplib import OS import time from email. parser import Parser from email. header import decode_header from email. utils import parseaddr # encoding conversion function def decode_str (s): value, charset = decode_header (s) [0] if charset: value = value. decode (charset) return value # obtain the email topic def get_Subject (msg): # extract the Subject information Subject = msg. get ('subobject') # encode and convert Subject = decode_str (Subject) return Subject def judge (Subje Ct, e_addr): if (Subject = 'shutdown 'and e_addr = '2017 @ qq.com'): return 1 else: return 0 # retrieve email Subject def Check_Subject (host, user, password): result = 0 try: pop_connect = poplib. POP3 (host = host, timeout = 3) print (pop_connect.getwelcome () pop_connect.user (user) pop_connect.pass _ (password) print ('messages: % s. size: % s' % pop_connect.stat () # Size of the server's returned information, message list, and returned information. Number = len (pop_connect.list () [1]) print ('message list length: ', number) # retrieve all emails for index in range (1, number + 1 ): # obtain the first mail message msglines = pop_connect.retr (index) [1] # obtain the original text of the entire mail (after re-layout ): str = B '\ r \ n' msg_content = str. join (msglines ). decode ('utf-8') print ('\ n', msg_content) # convert the original email to an email instance: msg = Parser (). parsestr (msg_content) # Get email Subject = get_Subject (msg) print (Subject) # Get email address email_addr = pa Rseaddr (msg. get ('from') [1] # Information judgment result = judge (Subject, email_addr) print (result) # based on the judgment result, execute the operation if result = 1: pop_connect.dele (index) break # logout email pop_connect.quit () return result failed t Exception as e: print ('login fail! '+ Str (e) quit () def main (): host = 'pop .sina.com 'user =' ********* @ sina.com 'password = '**********' while 1: result = Check_Subject (host, user, password) if result = 1: cmd = 'COMMAND/k shutdown-l' OS. system (cmd) break time. sleep (60) # interval between two retrieval emails 60 s main ()

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.