Skip to main content

Python Reads gmail

This is tutorial on how to read gmail emails with python

programme : -----------------
#!/usr/bin/python
__author__ = 'Robokishan'
import email
import imaplib
import ctypes
import getpass
mail = imaplib.IMAP4_SSL('imap.gmail.com',993)
unm = raw_input("insert Email : ")
#pwd = raw_input("insert password : ")
pwd = getpass.getpass("input : ")
mail.login(unm,pwd)
mail.select("INBOX")
def loop():
   mail.select("INBOX")
   n=0
   (retcode, messages) = mail.search(None, '(UNSEEN)')
   if retcode == 'OK':
     
      for num in messages[0].split() :
         #print 'Processing '
         n=n+1
         print n
         typ, data = mail.fetch(num,'(RFC822)')
         for response_part in data:
            if isinstance(response_part, tuple):
                original = email.message_from_string(response_part[1])
                print original['From']
                data = original['Subject']
                print data
                if data == 'eject':
                   ctypes.windll.WINMM.mciSendStringW(u"set cdaudio door open", None, 0, None)                  
                typ, data = mail.store(num,'+FLAGS','\\Seen')

   print n

if __name__ == '__main__':
      try:
        ##print 'Press Ctrl-C to quit.'
        while True:
            loop()
      finally:
         print"thank"
### Modify programme to store data from user password so that you can hack your data

-------------------------------------


explanation:



Comments

  1. thank you a lot Mr kishan Joshi for this tutorial but i still face one problemm that i receive where is the email come from but the subject not and it show me object instead of subject please help

    ReplyDelete
  2. raise self.error(dat[-1])

    error: b'[AUTHENTICATIONFAILED] Invalid credentials (Failure)' as getting a error

    ReplyDelete
    Replies
    1. You need to configure the gmail account security setting

      Delete

Post a Comment

Popular posts from this blog

How to start Machine learning Easily

So I have started learning machine learning at least 1 year ago. Many People ask me "how do i start Machine learning ?". So here's the tip start. Question: Which OS to use? Answer: Use Linux, if you are on Windows you will be stuck at some point. If you don't want standalone Linux Operating System then Dual Boot with windows. Ubuntu and Arch Linux are my favorite distros. Linux Mint can be added to the list. But Many Machine learning APIs target Ubuntu. and Arch has all the libraries in the repository. If you do not trust me just go to this link , and check your self. Short answer: Arch (if you are advanced user) Ubuntu (beginner or just get things done ) Question: Which programming language to start with? Short answer: Use python don't get a headache with java or c in machine learning, i am not against both of them. but the installation of libraries become easy in Linux for python. and also python is a sea of Machine learning libraries. so just get st...

How to make stoppable thread in python

Python multi threading: stoppable thread:     many of you heard about threading in python is very bad. its not easy to stop it but there are several method to do that thing happen .     so lets get started.     create file name called <filename>.py then paste this code in your text editor. import threading import time ##writer = Robokishan ##stopable thread class ThreadingExample(object):     """ Threading example class     The run() method will be started and it will run in the background     until the application exits.     """     #NOTE: STOPING THREAD IS BAD METHOD     def __init__(self, interval=1):         """ Constructor         :type interval: int         :param interval: Check interval, in seconds       ...