943,645 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 7590
  • Python RSS
Mar 31st, 2006
0

Receive e-mail

Expand Post »
I alredy know hoe to send e-mail by python but is possible to receive e-mail??
thanks for all post
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gYbU is offline Offline
3 posts
since Mar 2006
Apr 4th, 2006
0

Re: Receive e-mail

or how to delete all email
please
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gYbU is offline Offline
3 posts
since Mar 2006
Apr 4th, 2006
0

Re: Receive e-mail

I'm really confused what you're asking. Can you explain further please?
Administrator
Staff Writer
Reputation Points: 1422
Solved Threads: 162
The Queen of DaniWeb
cscgal is offline Offline
13,645 posts
since Feb 2002
Apr 4th, 2006
0

Re: Receive e-mail

I imagine you used the smtplib module and its functions to send e-mail. Well, you use the poplib module and its functions to view and delete e-mail.

Use help('poplib') to get details.

A rather crummy example is at
http://docs.python.org/lib/pop3-example.html
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Apr 4th, 2006
0

Re: Receive e-mail

Quote originally posted by cscgal ...
I'm really confused what you're asking. Can you explain further please?
YOu know password and username.You want to delete all of the mails in the box using python...
I alredy know how to send e-mail,how to receive.Thanks for all help
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gYbU is offline Offline
3 posts
since Mar 2006
Apr 7th, 2006
0

Re: Receive e-mail

Found code in one of the books in the CS library:
Python Syntax (Toggle Plain Text)
  1. # view and delete e-mail using the POP3 protocol
  2.  
  3. import sys, getpass, poplib, re
  4.  
  5. # change according to your needs
  6. POPHOST = "pop.domain.com"
  7. POPUSER = "joedoe"
  8. POPPASS = ""
  9. # the number of message body lines to retrieve
  10. MAXLINES = 10
  11. HEADERS = "From To Subject".split()
  12.  
  13. # headers you're actually interested in
  14. rx_headers = re.compile('|'.join(headers), re.IGNORECASE)
  15.  
  16. try:
  17. # connect to POP3 and identify user
  18. pop = poplib.POP3(POPHOST)
  19. pop.user(POPUSER)
  20.  
  21. if not POPPASS or POPPASS=='=':
  22. # if no password was supplied, ask for it
  23. POPPASS = getpass.getpass("Password for %s@%s:" % (POPUSER, POPHOST))
  24.  
  25. # authenticate user
  26. pop.pass_(POPPASS)
  27.  
  28. # get general information (msg_count, box_size)
  29. stat = pop.stat( )
  30.  
  31. # print some information
  32. print "Logged in as %s@%s" % (POPUSER, POPHOST)
  33. print "Status: %d message(s), %d bytes" % stat
  34.  
  35. bye = 0
  36. count_del = 0
  37. for n in range(stat[0]):
  38.  
  39. msgnum = n+1
  40.  
  41. # retrieve headers
  42. response, lines, bytes = pop.top(msgnum, MAXLINES)
  43.  
  44. # print message info and headers you're interested in
  45. print "Message %d (%d bytes)" % (msgnum, bytes)
  46. print "-" * 30
  47. print "\n".join(filter(rx_headers.match, lines))
  48. print "-" * 30
  49.  
  50. # input loop
  51. while 1:
  52. k = raw_input("(d=delete, s=skip, v=view, q=quit) What?")
  53. k = k[:1].lower( )
  54. if k == 'd':
  55. # Mark message for deletion
  56. k = raw_input("Delete message %d? (y/n)" % msgnum)
  57. if k in "yY":
  58. pop.dele(msgnum)
  59. print "Message %d marked for deletion" % msgnum
  60. count_del += 1
  61. break
  62. elif k == 's':
  63. print "Message %d left on server" % msgnum
  64. break
  65. elif k == 'v':
  66. print "-" * 30
  67. print "\n".join(lines)
  68. print "-" * 30
  69. elif k == 'q':
  70. bye = 1
  71. break
  72.  
  73. # done ...
  74. if bye:
  75. print "Bye"
  76. break
  77.  
  78. # summary
  79. print "Deleting %d message(s) in mailbox %s@%s" % (
  80. count_del, POPUSER, POPHOST)
  81.  
  82. # close operations and disconnect from server
  83. print "Closing POP3 session"
  84. pop.quit( )
  85.  
  86. except poplib.error_proto, detail:
  87.  
  88. # possible error
  89. print "POP3 Protocol Error:", detail
Reputation Points: 404
Solved Threads: 180
Nearly a Posting Virtuoso
bumsfeld is offline Offline
1,422 posts
since Jul 2005
Apr 20th, 2006
0

Re: Receive e-mail

hey, why i am getting this error..
can anyone explain me
Traceback (most recent call last):
File "popmail.py", line 14, in ?
rx_headers = re.compile('|'.join(headers), re.IGNORECASE)
NameError: name 'headers' is not defined
[B]
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sharma_vivek82 is offline Offline
18 posts
since Mar 2006
Apr 20th, 2006
0

Re: Receive e-mail

There is a booboo in the book, headers should be HEADERS.
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Printing
Next Thread in Python Forum Timeline: simple code to find a word in any page





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC