如何用python在hotmail中发送邮件?
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.
有没有人知道怎么写下面的代码?请帮帮我。我会非常感激的。
5 个回答
0
我觉得你可以看看这个模块:
http://docs.python.org/library/email.message.html
里面的解释非常清楚!我以前用过,真的很有帮助,而且很简单。虽然我不是用的hotmail,但应该也能用。
祝好,
Ste
0
查看email
这个包的文档:http://docs.python.org/library/email.html
里面有很多示例。
1
问题就在这里:
msg = "warning"
msg['From'] = "capstons2011jm4@hotmail.com"
msg['To'] = "yuxun88@hotmail.com"
msg['Subject'] = "hello"
msg是一个str
(字符串),而你却试图把它当成字典来使用,还想给它赋值。这是不对的。
你遇到的错误其实是在告诉你,字符串的某个位置是不能直接赋值的。