नहीं है नीचे कोड चल रहा है, मैं त्रुटि मिलती रहती है:आयात त्रुटि: 'email.mime' नामक कोई मॉड्यूल नहीं; ईमेल एक पैकेज
ImportError: No module named 'email.mime'; email is not a package
तो मैं चलाएँ:
pip install email
और प्राप्त निम्न त्रुटि:
ImportError: No module named 'cStringIO'...
Command "python setup.py egg_info" failed with error code 1
इंटरनेट ने मुझे चलाने के लिए कहा है:
pip install --upgrade pip
इस समस्या को हल करने के लिए, जिसे मैंने कई बार किया है। मुझे नहीं पता कि मैं और क्या कर सकता हूं।
पायथन संस्करण: पायथन 3.3.5 | एनाकोंडा 2.3.0 (x86_64)
import smtplib,email,email.encoders,email.mime.text,email.mime.base
smtpserver = 'ema[email protected]'
to = ['[email protected]']
fromAddr = '[email protected]'
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()
क्या आपके पास निर्देशिका में 'email.py' नामक एक फ़ाइल (या निर्देशिका) है जहां आप स्क्रिप्ट चला रहे हैं? या आपकी स्क्रिप्ट को 'email.py' भी कहा जाता है? – Evert
@ आगे बढ़ो, इस निर्देशिका में ईमेल नाम नहीं है। –
और क्या आपने पाइथन प्रॉम्प्ट से विभिन्न आयातों की कोशिश की है? '>> ईमेल आयात करें, '>>> आयात ईमेल.मेम'? – Evert