I'm writing my first Python program from scratch; it writes and sends an email based on user input for each variable. The first variable to define is the user's email server, which reads like this:
# Establish email server connection
print('Welcome to Brett\'s email program! Let\'s send a message.')
emailServer = input('First, I need your email provider: Gmail, Yahoo, or Outlook?\n')
The user enters their email provider, which should then name the variable from this list:
if emailServer == 'Gmail':
emailProvider = 'smtp.gmail.com'
if emailServer == 'Yahoo!':
emailProvider = 'smtp.mail.yahoo.com'
if emailServer == 'Yahoo':
emailProvider = 'smtp.mail.yahoo.com'
if emailServer == 'Outlook':
emailProvider = 'smtp.office365.com' # Found this server name on serversmtp.com
# TODO: Test other email providers (iCloud, AT&T, Comcast, Verizon)
else:
print('I don\'t know that email provider. Please try again.')
Every time I run the program in this instance, I get the else statement ('I don't know that email provider.'), and the program goes on to ask for the email address.
I've tried a couple different methods for handling these if/else statements. I've done elif statements, continue statements, break statements, and even a Boolean statement like this one:
if emailServer == 'Gmail' = True:
emailProvider = 'smtp.gmail.com'
None of them work. The program does work if I make Gmail the default value for emailProvider, so I know this is the bug section.
How do I make this section work? I think that putting the email provider info in a dictionary might do the trick, but I don't know how to implement that. I'm still learning as a developer, so giving an example of how the code would be organized (dictionary entry, proper elif statement) goes a long way towards comprehension. Thanks.
Aucun commentaire:
Enregistrer un commentaire