debian python 发送email提示初错: import email.utils ImportError: No module named utils
出错信息:Traceback(mostrecentcalllast):File"./emails.py",line6,in<module>fromemail.Header...
出错信息:
Traceback (most recent call last):
File "./emails.py", line 6, in <module>
from email.Header import Header
File "/home/pi/email.py", line 2, in <module>
File "/usr/lib/python2.7/smtplib.py", line 46, in <module>
import email.utils
ImportError: No module named utils
源代码是python2.7的
#!/usr/bin/env python
import os
import sys
curPath = os.path.abspath(os.path.dirname(__file__))
sys.path.append(curPath)
from email.Header import Header
import smtplib
mail_host = 'smtp.163.com'
mail_user = '***********@163.com'
mail_pwd = '***********'
mail_to = '***********@qq.com'
msg = MIMEMultipart()
att = MIMEText(open('/tmp/asd.txt','rb').read(),'base64','gb2312')
att["Content-Type"] = 'application/octet-stream'
att["Content-Disposition"] = 'attachment;filename="hello.txt"'
msg.attach(att)
message = 'content part'
body = MIMEText(message)
msg.attach(body)
msg['To'] = mail_to
msg['from'] = mail_user
msg['subject'] = 'this is a python test mail'
try:
s = smtplib.SMTP()
s.connect(mail_host)
s.login(mail_user,mail_pwd)
s.sendmail(mail_user,mail_to,msg.as_string())
s.close() 展开
Traceback (most recent call last):
File "./emails.py", line 6, in <module>
from email.Header import Header
File "/home/pi/email.py", line 2, in <module>
File "/usr/lib/python2.7/smtplib.py", line 46, in <module>
import email.utils
ImportError: No module named utils
源代码是python2.7的
#!/usr/bin/env python
import os
import sys
curPath = os.path.abspath(os.path.dirname(__file__))
sys.path.append(curPath)
from email.Header import Header
import smtplib
mail_host = 'smtp.163.com'
mail_user = '***********@163.com'
mail_pwd = '***********'
mail_to = '***********@qq.com'
msg = MIMEMultipart()
att = MIMEText(open('/tmp/asd.txt','rb').read(),'base64','gb2312')
att["Content-Type"] = 'application/octet-stream'
att["Content-Disposition"] = 'attachment;filename="hello.txt"'
msg.attach(att)
message = 'content part'
body = MIMEText(message)
msg.attach(body)
msg['To'] = mail_to
msg['from'] = mail_user
msg['subject'] = 'this is a python test mail'
try:
s = smtplib.SMTP()
s.connect(mail_host)
s.login(mail_user,mail_pwd)
s.sendmail(mail_user,mail_to,msg.as_string())
s.close() 展开
2个回答
2013-08-16
展开全部
顶leilmyxwz,说的对,我也遇到过,全卡死。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询