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()
我真的发现了如何使用python登录hotmail。
但是我用hotmail发邮件还是有问题。
TypeError: 'str' object does not support item assignment This keep coming up. I have no idea why.
有人知道怎么写下面的代码吗?请帮助。非常感谢。
问题就在这里:
msg = "warning"
msg['From'] = "capstons2011jm4@hotmail.com"
msg['To'] = "yuxun88@hotmail.com"
msg['Subject'] = "hello"
msg是一个str
,你试图把它当作一个字典,并试图给它赋值。这是错误的。
你得到的错误是试图说你不能给字符串中的索引位置赋值。
参见email
包的文档:http://docs.python.org/library/email.html
有很多例子
看起来你需要email
模块:
>>> 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
我想你也许可以看看这个模块:
http://docs.python.org/library/email.message.html它解释得很好!我以前用过,真的很有帮助,也很容易。(我没有使用hotmail,但它应该可以工作)
最好的,Ste
这对我有好处
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()