如何使用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'] = "[email protected]"
msg['To'] = "[email protected]"
msg['Subject'] = "hello"
s = smtplib.SMTP("smtp.live.com",25)
s.sendmail("[email protected]", "[email protected]", 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.
有谁知道下面的代码怎么写。请帮忙。我将非常感激。
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'] = "[email protected]"
msg['To'] = "[email protected]"
msg['Subject'] = "hello"
s = smtplib.SMTP("smtp.live.com",25)
s.sendmail("[email protected]", "[email protected]", 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
问题就在这里:
msg 是一个
str
并且您试图将其视为字典并尝试为其分配值。这是错误的。您收到的错误试图说明您无法为字符串中的索引位置分配值。
The problem is right here:
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.
请参阅
email
包的文档:http://docs.python。 org/library/email.html有很多示例 。
See the documentation for the
email
package: http://docs.python.org/library/email.htmlThere are a lot of examples.
看起来您需要
email
模块:It looks like you need
email
module:我想你可能会先看看这个模块:
http://docs.python.org /library/email.message.html
它解释得很好!
我过去使用过,非常有帮助且简单。
(我没有使用 hotmail,但它应该也能工作)
最好,
斯特
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
这对我有好处
it's good for me