关于python2.6.5下的 smtplib 问题

changboter 发布于 2011/04/29 10:35
阅读 927
收藏 1

用python 的  smtplib 做例子,总是出错,以下为出错

 

 

File "email.py", line 1, in <module>

    import smtplib

  File "/usr/local/lib/python2.6/smtplib.py", line 46, in <module>

    import email.utils

  File "/home/pythonlib/email.py", line 2, in <module>

    from email.mime.text import MIMEText

ImportError: No module named mime.text

 

 

以下为代码:

 

import smtplib

from email.mime.text import MIMEText

 

fromaddr = 'chang@gmail.com'

toaddrs  = 'chang@qq.com'

msg = MIMEText('hello world')

msg['Subject'] = 'I miss you'

msg['From'] = 'chang@gmail.com'

msg['To'] = 'chang@qq.com'

 

# Credentials (if needed)

username = 'chang'

password = '××××××××'

 

# The actual mail send

server = smtplib.SMTP('smtp.gmail.com:587')

server.starttls()

server.login(username,password)

server.sendmail(fromaddr, toaddrs, msg.as_string())

server.quit()

 

实在看不出错误,是PYTHON版本的问题? 我的运行环境是  centos5.5   python2.6.5

加载中
0
asdfsx
asdfsx

from email.MIMEText import MIMEText

你完全写错了吧

ImportError: No module named mime.text写的很明确啊

0
changboter
changboter

但是是有那个模块的,我进安装包里看了

返回顶部
顶部