Authentication
Simon Forman
rogue_pedro at yahoo.com
Wed Jul 19 12:13:19 EDT 2006
bigodines wrote:
> Hello guys,
>
> I'm trying to learn python by making some small programs that could be
> useful for some bigger propouses. In fact, i've made a small "check
> latest-modified" for webpages and it's working great.
>
> The next step I would like to do is to check if I have new e-mails (I
> don't wanna read it from my program, i just wanna it to tells me "yes,
> you have new mail(s)" or "no".
>
> My question is, how do I log into my google account using urllib2 to
> check this? Does anyone have a sample script that I can use or
> something to help me?
>
> thanks in advice,
> Matheus
Gmail supports pop and smtp access. See
http://docs.python.org/lib/module-poplib.html and
http://docs.python.org/lib/module-smtplib.html, as well as
http://mail.google.com/support/bin/answer.py?answer=13273 and
http://mail.google.com/support/bin/answer.py?answer=13287
Here's a simple pop script:
import poplib
me = 'your.username at gmail.com'
p = '*******' # put your real password of course..
host ='pop.gmail.com'
pop = poplib.POP3_SSL(host)
try:
pop.user(me)
pop.pass_(p)
message_count, mailbox_size = pop.stat()
# Do some more stuff here...
finally:
pop.quit()
print message_count, mailbox_size
And a simple smtp script:
import smtplib
me = 'your.username at gmail.com'
p = '*******' # put your real password of course..
server = smtplib.SMTP('smtp.gmail.com', 587)
try:
server.ehlo()
server.starttls()
server.ehlo()
server.login(me, p)
# Do some more stuff here...
finally:
server.close()
HTH,
~Simon
More information about the Python-list
mailing list