1
import poplib

M = poplib.POP3_SSL('pop3.live.com', 995) #Connect to hotmail pop3 server

try: 

    M.user(raw_input("username: ")) #Get the username from the standar input
    M.pass_(raw_input("password: ")) #Get the password from the standar input
except:

    print "username or password incorrect"
else:

    print "Successful login"

import smtplib

msg = "warning"

msg['From'] = "capstons2011jm4@hotmail.com"

msg['To'] = "yuxun88@hotmail.com"

msg['Subject'] = "hello"

s = smtplib.SMTP("smtp.live.com",25)

s.sendmail("capstones2011jm4@hotmail.com", "yuxun88@hotmail.com", msg.as_string())

s.quit()

I arealy found out how to login hotmail using python.

But I still have trouble about send email in hotmail.

TypeError: 'str' object does not support item assignment  This keep coming up. I have no idea why.

Does anyone know how to write the following code. Plz help. I will so appreciate that.

Senthil Kumaran
  • 54,681
  • 14
  • 94
  • 131
Yuxun Hu
  • 11
  • 1
  • 2

5 Answers5

1

The problem is right here:

msg = "warning"
msg['From'] = "capstons2011jm4@hotmail.com"
msg['To'] = "yuxun88@hotmail.com"
msg['Subject'] = "hello"

msg is a str and you are trying to treat it like a dictionary and trying to assign values to it. This is wrong.

The error you are getting is trying to say that you cannot assign values to index position in the string.

Senthil Kumaran
  • 54,681
  • 14
  • 94
  • 131
0

it's good for me

 import email
 import smtplib

 msg = email.message_from_string('warning')
 msg['From'] = "example@hotmail.fr"
 msg['To'] = "example@hotmail.fr"
 msg['Subject'] = "helOoooOo"

 s = smtplib.SMTP("smtp.live.com",587)
 s.ehlo()
 s.starttls() 
 s.ehlo()
 s.login('example@hotmail.fr', 'pass')


 s.sendmail("example@hotmail.fr", "example@hotmail.fr", msg.as_string())

 s.quit()
levasseur
  • 171
  • 1
  • 3
  • Could you please provide more information why your code will solve the questioners problem? – morkro Aug 09 '14 at 16:33
0

See the documentation for the email package: http://docs.python.org/library/email.html

There are a lot of examples.

codeape
  • 97,830
  • 24
  • 159
  • 188
0

It looks like you need email module:

>>> import email
>>> msg = email.message_from_string('warning')
>>> msg['From'] = "capstons2011jm4@hotmail.com"
>>> msg['To'] = "yuxun88@hotmail.com"
>>> msg['Subject'] = "hello"
>>> print msg.as_string()
From: capstons2011jm4@hotmail.com
To: yuxun88@hotmail.com
Subject: hello

warning
Roman Bodnarchuk
  • 29,461
  • 12
  • 59
  • 75
0

i think you may prehaps give a look to this module:

http://docs.python.org/library/email.message.html

it's explained quite well! I used in the past and was really helpful and easy. (I was not using hotmail but it should work as well)

Best, Ste

Stefano
  • 3,981
  • 8
  • 36
  • 66