2016-11-05 2 views
1

Dieser Code ist" annehmen ", um eine E-Mail zu senden.Getting error `Kein Modul mit dem Namen mime.text` [Python]

import smtplib 
#SERVER = "localhost" 

FROM = '[email protected]' 

TO = ["[email protected]"] # must be a list 

SUBJECT = "Hello!" 

TEXT = "This message was sent with Python's smtplib." 

# Prepare actual message 

message = """\ 
From: %s 
To: %s 
Subject: %s 

%s 
""" % (FROM, ", ".join(TO), SUBJECT, TEXT) 

# Send the mail 

server = smtplib.SMTP('myserver') 
server.sendmail(FROM, TO, message) 
server.quit() 

Ich bekomme diese Fehlermeldung.

Traceback (most recent call last): 
    File "C:\Users\myCpu\Documents\myFiles\python\test wy.py", line 1, in <module> 
    import smtplib 
    File "C:\Python27\lib\smtplib.py", line 46, in <module> 
    import email.utils 
    File "C:/Users/myCpu/Documents/myFiles/python\email.py", line 5, in <module> 
ImportError: No module named mime.text 

Verwendung:

Python 2.7

Windows 7 Professionnal

Gmail (@ gmail.com)


Kann mir jemand helfen mit th ist Code?

Antwort

3

Benennen Sie die Datei, die Sie auf dem Namen email.py auf etwas anderes arbeiten. Es wird wahrscheinlich Importe in Ihren Bibliotheken brechen.

+0

Das bekomme ich: 'server = smtplib.SMTP ('myserver') Datei" C: \ Python27 \ lib \ smtplib.py ", Zeile 256, in __init__ (code, msg) = self. connect (host, port) Datei "C: \ Python27 \ lib \ smtplib.py", Zeile 316, in Verbindung self.sock = self._get_socket (Host, Port, self.timeout) Datei "C: \ Python27 \ lib \ smtplib.py ", Zeile 291, in _get_socket zurücksenden socket.create_connection ((host, port), timeout) Datei" C: \ Python27 \ lib \ socket.py ", Zeile 557, in create_connection für res in getaddrinfo (Host, Port, 0, SOCK_STREAM): gaierror: [Errno 11004] getaddrinfo fehlgeschlagen ' –

2

Dies ist, was ich für Google Mail getan habe. Hope this Sloves Ihr Problem

from email.mime.text import MIMEText 

    def construct_mesage(): 
     message = MIMEText(message_text) 
     message['to'] = to 
     message['from'] = sender 
     message['subject'] = subject 
     return {'raw': base64.urlsafe_b64encode(message.as_string())} 
+0

Leite ich das einfach ?? oder ist etwas anderes nötig ?? –

+0

Dies gibt Ihnen ein rohes Objekt, das Sie dies trennen können –

+0

Ich bekomme das jetzt: 'Kein Modul namens utils –

Verwandte Themen