我使用下面的代码从Python程序在本地主机发送电子邮件发送电子邮件,无法从蟒蛇
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
me = "[email protected]"
you = "[email protected]"
msg = MIMEMultipart('alternative')
msg['Subject'] = "Link"
msg['From'] = me
msg['To'] = you
text = "Hi!\nHow are you?\nHere is the link you wanted:\nhttp://www.python.org"
html = """\
<html>
<head></head>
<body>
<p>Hi!<br>
How are you?<br>
Here is the <a href="http://www.python.org">link</a> you wanted.
</p>
</body>
</html>
"""
part1 = MIMEText(text, 'plain')
part2 = MIMEText(html, 'html')
msg.attach(part1)
msg.attach(part2)
s = smtplib.SMTP('localhost',5000)
s.sendmail(me, you, msg.as_string())
s.quit()
此代码是从Python文档。
当我运行此代码时,它连续运行,但没有发送电子邮件。
我想知道,除了这段代码外,我还必须在其他地方做一些其他配置。
我没有看到任何错误。
我使用python 2.7
这是作为在Sending HTML email using Python
你的代码试图利用SMTP服务器在本地主机端口5000 –
@TimothéeJeannin上发送电子邮件对不起,我是新来这整个事情能你告诉我我该怎么做? –