Sunday, 15 March 2015

email - reading mails using python -


How can I use Python from my mailbox ??

  import getpass, Imaplib M = imaplib.IMAP4 ('IMAP4.gmail.com:993') mlogin (getpass.getuser (), getpass.getpass ()) m. Selection () type, data = m. [0] .split (): for the zero in the search (none, 'ALL') data type, data = M.fetch (num, '(RFC822)') print message '% s \ n% s \ n' % (Num, data [0] [1]) m. Close (M) Logout ()  

This is my code. But when I execute its throwing error:

  traceback (most recent call final): The file "e: / jagdish / python progs / readmail.py", line 2, & lt; Module & gt; M = imaplib.IMAP4 ('IMAP4.gmail.com:993') file "C: \ Python25 \ lib \ imaplib.py", line 163, __init__ in self.open (host, port) file "C: \ Python25 \ Lib \ imaplib.py ", line 230, in open self.sock.connect (" host, port ") file" string "; line1, in connect gear: (11001, 'Getaddrinfo failed')  

Can anyone help me with this ???

Three issues:

  1. Hostname imap.gmail imap4.gmail.com
  2. IMAP4 creator takes two parameters: host and port (not separate from colon)
  3. Gmail expects you to talk to the SSL

like this:

  import imaplib m = imaplib.IMAP4_SSL ("imap.gmail.com", 993 )  

No comments:

Post a Comment