简体   繁体   中英

How to input email address with smtplib

I can't find an email app that I like, so I decided to make my own. I'm using smtplib and python to do so. In the basic email file, I'm trying to let the user input the address they want to send to. The first issue is that it won't accept the '@' sign, saying it's invalid syntax. To get around this I put an underscore instead of the @ sign and However, it started saying the entire email address is undefined. What I think is messing it up is the '.com' at the end. I attached the error message. If anyone knows how to fix this please let me know.

Nats-Air:~ nattaylor$ python 
/Users/nattaylor/Programming/Email/plainEmail.py
Reciever: nathanielptaylor_gmail.com
Traceback (most recent call last):
File 
"/Users/nattaylor/Programming/Email/plainEmail.py", 
line 8, in <module>
toaddress = input('Reciever: ')
File "<string>", line 1, in <module>
NameError: name 'nathanielptaylor_gmail' is not defined

In Python 2, the input() function tries to evaluate the user's input as though it were a Python expression. This is rarely a good idea. Use raw_input() instead to just get a string from the user.

我在所有输入上都使用了raw_input,而不是常规输入,并且有效。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM