如何使用python在hotmail中写邮件?

发布于 2024-11-26 10:03:14 字数 1368 浏览 2 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

假情假意假温柔 2024-12-03 10:03:14

问题就在这里:

msg = "warning"
msg['From'] = "[email protected]"
msg['To'] = "[email protected]"
msg['Subject'] = "hello"

msg 是一个 str 并且您试图将其视为字典并尝试为其分配值。这是错误的。

您收到的错误试图说明您无法为字符串中的索引位置分配值。

The problem is right here:

msg = "warning"
msg['From'] = "[email protected]"
msg['To'] = "[email protected]"
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.

累赘 2024-12-03 10:03:14

请参阅 email 包的文档:http://docs.python。 org/library/email.html

有很多示例

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

There are a lot of examples.

北方的巷 2024-12-03 10:03:14

看起来您需要 email 模块:

>>> import email
>>> msg = email.message_from_string('warning')
>>> msg['From'] = "[email protected]"
>>> msg['To'] = "[email protected]"
>>> msg['Subject'] = "hello"
>>> print msg.as_string()
From: [email protected]
To: [email protected]
Subject: hello

warning

It looks like you need email module:

>>> import email
>>> msg = email.message_from_string('warning')
>>> msg['From'] = "[email protected]"
>>> msg['To'] = "[email protected]"
>>> msg['Subject'] = "hello"
>>> print msg.as_string()
From: [email protected]
To: [email protected]
Subject: hello

warning
乱世争霸 2024-12-03 10:03:14

我想你可能会先看看这个模块:

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

镜花水月 2024-12-03 10:03:14

这对我有好处

 import email
 import smtplib

 msg = email.message_from_string('warning')
 msg['From'] = "[email protected]"
 msg['To'] = "[email protected]"
 msg['Subject'] = "helOoooOo"

 s = smtplib.SMTP("smtp.live.com",587)
 s.ehlo()
 s.starttls() 
 s.ehlo()
 s.login('[email protected]', 'pass')


 s.sendmail("[email protected]", "[email protected]", msg.as_string())

 s.quit()

it's good for me

 import email
 import smtplib

 msg = email.message_from_string('warning')
 msg['From'] = "[email protected]"
 msg['To'] = "[email protected]"
 msg['Subject'] = "helOoooOo"

 s = smtplib.SMTP("smtp.live.com",587)
 s.ehlo()
 s.starttls() 
 s.ehlo()
 s.login('[email protected]', 'pass')


 s.sendmail("[email protected]", "[email protected]", msg.as_string())

 s.quit()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文