0

I'm creating an account creator. I am hoping I can create an email sender so people receive an email after filling in a form, this is what I've tried:

# Import smtplib for the actual sending function
import smtplib

# Import the email modules we'll need
from email.mime.text import MIMEText

# Open a plain text file for reading.  For this example, assume that
# the text file contains only ASCII characters.
fp = open('textfile.txt', 'rb')
# Create a text/plain message
msg = MIMEText(fp.read())
fp.close()

# me == the sender's email address
# you == the recipient's email address
msg['Subject'] = 'The contents of %s' % textfile
msg['From'] = me
msg['To'] = you

# Send the message via our own SMTP server, but don't include the
# envelope header.
s = smtplib.SMTP('localhost')
s.sendmail(me, [you], msg.as_string())
s.quit()

I try renaming the file to main.py , but I just get the error:

Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 2218, in _find_and_load_unlocked
AttributeError: 'module' object has no attribute '__path__'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/macbook/Movies/GAME/*********/3D/email.py", line 2, in <module>
    import smtplib
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/smtplib.py", line 47, in    <module>
    import email.utils
  File "/Users/macbook/Movies/GAME/*********/3D/email.py", line 5, in <module>
    from email.mime.text import MIMEText
ImportError: No module named 'email.mime'; 'email' is not a package

when I changed the name of the file to main.py I get the error:

Traceback (most recent call last):
  File "/Users/macbook/Movies/GAME/Wonderland/3D/main.py", line 11, in <module>
    msg = MIMEText(fp.read())
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/email/mime/text.py", line 33, in __init__
    _text.encode('us-ascii')
AttributeError: 'bytes' object has no attribute 'encode'

there is lots of other python email sender questions but none have the same issues/errors as I do.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Random Person
  • 399
  • 1
  • 3
  • 9

1 Answers1

1

Change the name of your email.py file. It is masking the email package you want to use. Delete email.pyc as well

joel goldstick
  • 4,393
  • 6
  • 30
  • 46
  • Traceback (most recent call last): File "/Users/macbook/Movies/GAME/3D/main.py", line 11, in msg = MIMEText(fp.read()) File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/email/mime/text.py", line 33, in __init__ _text.encode('us-ascii') AttributeError: 'bytes' object has no attribute 'encode' – Random Person Aug 30 '16 at 19:16
  • I don't understand your comment @TheBigFatPig. Did you change the file name of your program? what happened after that? – joel goldstick Aug 30 '16 at 19:20
  • that error came up – Random Person Aug 30 '16 at 19:23
  • Put the new traceback in your question, and format it – joel goldstick Aug 30 '16 at 21:03