运行以下代码时,我不断收到错误:
ImportError: No module named 'email.mime'; email is not a package
Run Code Online (Sandbox Code Playgroud)
所以我跑:
pip install email
Run Code Online (Sandbox Code Playgroud)
并得到以下错误:
ImportError: No module named 'cStringIO'...
Command "python setup.py egg_info" failed with error code 1
Run Code Online (Sandbox Code Playgroud)
互联网告诉我运行:
pip install --upgrade pip
Run Code Online (Sandbox Code Playgroud)
要解决这个问题,我现在做了很多次.我不知道还能做些什么.
Python版本:Python 3.3.5 | Anaconda 2.3.0(x86_64)
import smtplib,email,email.encoders,email.mime.text,email.mime.base
smtpserver = 'email@site.com'
to = ['address@gmail.com']
fromAddr = 'email@site.com'
subject = "testing email attachments"
# create html email
html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" '
html +='"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">'
html +='<body style="font-size:12px;font-family:Verdana"><p>...</p>'
html += "</body></html>"
emailMsg = email.MIMEMultipart.MIMEMultipart('text/csv')
emailMsg['Subject'] = subject
emailMsg['From'] = fromAddr
emailMsg['To'] = ', '.join(to)
emailMsg['Cc'] = ", ".join(cc)
emailMsg.attach(email.mime.text.MIMEText(html,'html'))
# now attach the file
fileMsg = email.mime.base.MIMEBase('text/csv')
fileMsg.set_payload(file('rsvps.csv').read())
email.encoders.encode_base64(fileMsg)
fileMsg.add_header('Content-Disposition','attachment;filename=rsvps.csv')
emailMsg.attach(fileMsg)
# send email
server = smtplib.SMTP(smtpserver)
server.sendmail(fromAddr,to,emailMsg.as_string())
server.quit()
Run Code Online (Sandbox Code Playgroud)
Yue*_*eng 60
我刚才遇到了同样的问题.最后,我发现这是因为我将python文件命名为'email.py'.它在更改名称后起作用.
Sup*_*ohn 15
问题在于pip.我无法使用更新setuptools
easy_install --upgrade setuptools
Run Code Online (Sandbox Code Playgroud)
我也无法使用pip安装电子邮件
pip install email
Run Code Online (Sandbox Code Playgroud)
我通过使用easy_install安装电子邮件来解决问题
easy_install email
Run Code Online (Sandbox Code Playgroud)
希望有人发现这有帮助.感谢那些帮助过的人.
| 归档时间: |
|
| 查看次数: |
37630 次 |
| 最近记录: |