PDA

View Full Version : Help with python!



B4RR13N705
April 27th, 2009, 04:34 PM
Hi, im starting with python, and today i was bored :) so i decided to make some stuff with python. I want to make a script that connects to a Hotmail account under python. I get sucked on this.
How can i connect to a hotmail account under python?
Somebody please post a piece of code :popcorn:

ghostdog74
April 27th, 2009, 04:54 PM
learn about the basics of Python first before even doing that.

ajackson
April 27th, 2009, 06:34 PM
Hi, im starting with python, and today i was bored :) so i decided to make some stuff with python. I want to make a script that connects to a Hotmail account under python. I get sucked on this.
How can i connect to a hotmail account under python?
Somebody please post a piece of code :popcorn:
This isn't rentacoder you know. What have you done so far? What problems have you hit? When is this coursework due in :)?

B4RR13N705
April 27th, 2009, 08:48 PM
Actually is a script for a screenlet-like. I write all the other stuff. It actually works, showing on the desktop the Hotmail Icon and a number of unread mails. The problem is that i cant figured out how to connect to a hotmail account. I did something similar with gmail, that allows you to write mail with python:


import smtplib

FROMADDR = "mail@gmail.com"
LOGIN = FROMADDR
PASSWORD = "password"
TOADDRS = ["mailto@gmail.com"]
SUBJECT = "Test"

msg = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n"
% (FROMADDR, ", ".join(TOADDRS), SUBJECT) )
msg += "some text that you can send\r\n"

server = smtplib.SMTP('smtp.gmail.com', 587)
server.set_debuglevel(1)
server.ehlo()
server.starttls()
server.login(LOGIN, PASSWORD)
server.sendmail(FROMADDR, TOADDRS, msg)
server.quit()


Im not totally beginner, i think i expressed myself wrong :confused:
Can anybody point me in the right direction?

joey-elijah
April 27th, 2009, 08:55 PM
Actually is a script for a screenlet-like. I write all the other stuff. It actually works, showing on the desktop the Hotmail Icon and a number of unread mails. The problem is that i cant figured out how to connect to a hotmail account. I did something similar with gmail, that allows you to write mail with python:


import smtplib

FROMADDR = "mail@gmail.com"
LOGIN = FROMADDR
PASSWORD = "password"
TOADDRS = ["mailto@gmail.com"]
SUBJECT = "Test"

msg = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n"
% (FROMADDR, ", ".join(TOADDRS), SUBJECT) )
msg += "some text that you can send\r\n"

server = smtplib.SMTP('smtp.gmail.com', 587)
server.set_debuglevel(1)
server.ehlo()
server.starttls()
server.login(LOGIN, PASSWORD)
server.sendmail(FROMADDR, TOADDRS, msg)
server.quit()
Im not totally beginner, i think i expressed myself wrong :confused:
Can anybody point me in the right direction?

Sorry, what are you trying to do? You said your hotmail screenlet works and shows the unread count fine. Well that's great already!

You want to be able to write an e-mail in the screenlet and send it? Wow! That would pretty nice, if very complex.

So.. why are you posting code for GMail?

B4RR13N705
April 27th, 2009, 09:02 PM
I think i counfused you even more :lolflag:
Im doing that hotmail screenlet, i cant figure the way to connect to a hotmail account yet. About the gmail code, i was just puting an example, just ignore it.
The point is:
How to connect to a hotmail account under python??

croto
April 28th, 2009, 12:54 AM
I would start by making sure there's no library that does what you want to do. If not, and you wanna do it yourself, let me tell you that even though it isn't impossinle to do , it is not trivial either, and you'll have to sweat a bit. Hotmail is not a service that is designed to be accessed programmatically, the idea is that you'll have to mimick what the browser does when you login and access your account. In principle you'll have to:

1) Request the login web page: for that you can use python's urllib2 library. It'll make you're life easier because you'll have to establish an ssl connection to the server and also manage the cookies given by it. The cookies will allow to maintain the session - it is strictly necessary.

2) Probably you'll have to fill in a form (with username and password and least) and send it to the server. Urllib2 will come in your help for that. But in order to know what url you have to send the post to, what fields to fill, etc. you'll have to parse the login web page. You might end up doing some regular expressions for that purpose.

3) Access your folders, emails, etc: most probably there will be different http posts you'll have to do in order to get folders and emails. It may help to run a packet analyzer and check exactly what the browser is telling the server (which I guess will be http posts) and do the same thing from your program.

If you've never done anything like what I was trying to describe, consider this as a research project. Basically you'll have to reverse engineer the communication between your browser and hotmail and replicate it.

Good luck!

B4RR13N705
April 28th, 2009, 01:18 AM
mmm, i think i have some ideas in mind, it will not be that easy :) but it will not be impossible :P
Thanx for the help! you just pointed me in the right direction.

B4RR13N705
April 28th, 2009, 01:33 AM
I touch the light! :KS
Im just making some tests, i will base my project to the way that "lynx" do it!

croto
April 28th, 2009, 01:35 AM
mendocino eh?

simeon87
April 28th, 2009, 12:39 PM
Hotmail also has POP3 support so it's probably easier to use that instead of requesting the login page and all that.

nvteighen
April 28th, 2009, 02:45 PM
Check if there is any Hotmail API documentation. If not, the POP3 solution might be the sanest way to do this.

B4RR13N705
April 28th, 2009, 04:26 PM
Ive searched for API documentation but i didnt found anything :confused: I thought about POP3 before, it seems to be a much easier way!

B4RR13N705
April 28th, 2009, 04:32 PM
ive found some suff about POP3


POP server: pop3.live.com (Port 995)
¿POP SSL required? YES
User name: Your Windows Live ID
Password: Your Password
SMTP server: smtp.live.com (Port 25)
¿TLS/SSL Required? YES