0

I got the script from the first example here: https://docs.python.org/2/library/email-examples.html#email-examples

I made sure there is no file name similar to email.py.

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

fp = open(textfile, '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'] = torontocoinowl@gmail.com
msg['To'] = torontocoinowl@gmail.com

# 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()

The error is

C:\Users\donald\AppData\Local\Programs\Python\Python35-32\python.exe C:/Users/donald/PycharmProjects/untitled3/testingemail/ff.py
Traceback (most recent call last):
  File "C:/Users/donald/PycharmProjects/untitled3/testingemail/ff.py", line 1, in <module>
    import smtplib
  File "C:\Users\donald\AppData\Local\Programs\Python\Python35-32\lib\smtplib.py", line 47, in <module>
    import email.utils
  File "C:\Users\donald\AppData\Local\Programs\Python\Python35-32\lib\email\utils.py", line 28, in <module>
    import random
  File "C:\Users\donald\PycharmProjects\untitled3\random.py", line 1
    From random import randint
              ^
SyntaxError: invalid syntax

Process finished with exit code 1
donald
  • 1
  • 1

1 Answers1

0

You are having a file random.py in your folder. It clashes with the random modul in Python. Remove of rename that file!

Klaus D.
  • 13,874
  • 5
  • 41
  • 48