0

I have a script for sending emails using SMTP_SSL. The code is working fine in PyCharm but in the terminal I get an error.

This is the code:

import  smtplib
s = smtplib.SMTP_SSL("smtp.googlemail.com:465")
mml=input("enter your email address :\n")
str(mml)
passr=input("enter your pass:\n")
str(passr)
s.login(mml,passr)
em = input("please type the email you want to send :\n")
str(em)
a = input("please type the message:\n")

    str(a)
    s.sendmail(mml,em,a)

print("\nEmail Was Sent..:)")

When I run this in my terminal its giving this after i enter the email:

enter your email address :
mahmoud.wizzo@gmail.com
Traceback (most recent call last):
File "medo.py", line 3, in <module>
mml=input("enter your email address :\n")
File "<string>", line 1
mahmoud.wizzo@gmail.com
             ^
SyntaxError: invalid syntax

When I am trying to put the email between quotes, e.g. "mahmoud.wizzo@gmail.com" its working fine.

How can I run my script in the terminal?

ivan_pozdeev
  • 33,874
  • 19
  • 107
  • 152
Mody963Cz
  • 29
  • 8
  • What are `str(mml)`, `str(passr)`, `str(em)`, and `str(a)` supposed to do? – ChrisGPT was on strike May 20 '18 at 17:19
  • 1
    Why are `str(a)` and `s.sendmail(mml,em,a)` indented? Whitespace is significant in Python—you should get an `IndentationError` here. Please make sure your question _exactly_ reflects your code. We have no way of knowing which errors are significant. – ChrisGPT was on strike May 20 '18 at 17:21
  • i dont have space before str(a) and s.sendmail(mml,em,a) just thats by wrong when posting – Mody963Cz May 20 '18 at 17:27
  • @Chris in the terminal when i type the email i get the error but when type it between "" its work fine – Mody963Cz May 20 '18 at 17:31
  • 1
    With that indentation error the script won't run. Please make sure the code in your question _exactly_ reflects the code on your machine. – PM 2Ring May 20 '18 at 17:34

2 Answers2

3

I suspect you're running your script using Python 2 on the command line. The behaviour of input() changed in Python 3.

Try running python3 my_file.py instead of python my_file.py.

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
1

This is actually the way Python works. The problem you have is that input takes input from the user and then "executes" or "compiles" it so if you enter 4+9 in the input it will produce the number 13. Not the string "4+9". So try using raw_input() in Python 2. You can also use sys.stdin.readline() to get a string I'm any Python version. Don't forget import sys.

Preston Hager
  • 1,514
  • 18
  • 33