Hello, new coder here :-)
I've been working on one of my first scripts, an SMTP script for sending mail with Gmail.
It works and all, but I wan't to have an "if" the login to the server failed, it would print and message saying so and return to the beginning.
gname = raw_input("Username: ")
gpass = getpass.getpass("Password: ")
server = smtplib.SMTP('smtp.gmail.com:587')
server.ehlo()
server.starttls()
server.ehlo()
server.login(gname,gpass)
The first part is where the user inputs the login data, and then it continues the to try and log onto the Gmail account. If at first I spell my username incorrectly, or type the wrong password, I get "SMTPAuthenticationError".
So what I'm trying to produce is something like this:
if smtplib.SMTPAuthenticationError:
print "Error! Wrong password or username."
else:
print "Logged in as ", gname
But it doesn't work (mainly because I don't know how to "if" it), and I haven't found any specific information that would point me in the right direction for an solution.
Is there anyone that are willing to help me? Not necessary give the solution in text, but like give me some hints.
Thanks in advance!