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 : [email protected] Traceback (most recent call last): File "medo.py", line 3, in <module> mml=input("enter your email address :\n") File "<string>", line 1 [email protected] ^ SyntaxError: invalid syntax 

When I am trying to put the email between quotes, e.g. "[email protected]" its working fine.

How can I run my script in the terminal?

5
  • What are str(mml), str(passr), str(em), and str(a) supposed to do? Commented May 20, 2018 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. Commented May 20, 2018 at 17:21
  • i dont have space before str(a) and s.sendmail(mml,em,a) just thats by wrong when posting Commented May 20, 2018 at 17:27
  • @Chris in the terminal when i type the email i get the error but when type it between "" its work fine Commented May 20, 2018 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. Commented May 20, 2018 at 17:34

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.