2828
2929l = "smtp.gmail.com"
3030s = smtplib .SMTP (l , 587 )
31+ listLen = 0
3132
3233class email :
3334 def save ():
35+ print (emails )
36+ print (names )
3437 theLists = open ("lists.py" , "w" )
3538 stringToSave = 'names = ['
36- for i in range (len (names )- 2 ):
39+ for i in range (len (names )- 1 ):
3740 stringToSave = stringToSave + '"' + names [i ]+ '",'
3841 stringToSave = stringToSave + '"' + names [(len (names )- 1 )]+ '"]\n emails = ['
3942 i = 1
40- for i in range (len (emails )- 2 ):
43+ for i in range (len (emails )- 1 ):
4144 stringToSave = stringToSave + '"' + emails [i ]+ '",'
4245 stringToSave = stringToSave + '"' + emails [(len (emails )- 1 )]+ '"]'
43- theLists .write (stringToSave )
46+ theLists .write (str ( stringToSave ) )
4447 print (stringToSave )
4548 def loginSMTP ():
4649 provider = input ("What provider do you want to use Gmail(G), Outlook(O), Yahoo(Y), AOL(A) \n " )
47- #if(provider == "G"):
48- # l = 'smtp.gmail.com'
49- #elif(provider == "Y"):
50- # l = 'smtp.mail.yahoo.com'
51- #elif(provider == "O"):
52- # l = 'smtp-mail.outlook.com'
53- #elif(provider == "A"):
54- # l = 'smtp.aol.com'
55- #else:
56- # print("that provider is not supported")
57- #s = smtplib.SMTP(l, 587)
5850 theirUsername = str (input ("What is your username \n " ))
5951 password = str (input ("What is your password \n " ))
60- print ("Debug Info: Username, " + username + " Password, " + password )
52+ print ("Debug Info: Username, " + theirUsername + " Password, " + password )
6153 # Authentication
6254 try :
6355 s .starttls ()
@@ -66,53 +58,69 @@ def loginSMTP():
6658 print ("Debug Info: TLS Failed" )
6759 try :
6860 s .login (str (theirUsername ), str (password ))
69- print ("Succesful you are now logged in and can send emails" )
61+ print ("Debug Info: Succesful you are now logged in and can send emails\n \n " )
7062 except :
71- print ("It did not work " )
63+ print ("Debug Info: Login Failed \n \n " )
7264 def addEmail ():
7365 nameInput = str (input ("What is the Name you would like to append\n " ))
7466 names .append (nameInput )
7567 emailInput = str (input ("What is the email of the reciver\n " ))
7668 emails .append (emailInput )
77- email .save
69+ email .save ()
7870 def removeEmail ():
79-
80- listLen = len (emails )- 1
81- print ("the email" , emails (listLen - 1 ), "was removed" )
82- emails .remove (listLen )
83- names .remove (listLen )
84- emails .save
85- names .save
86-
71+ removeName = input ("What is the name you want to remove\n " )
72+ listLen = 0
73+ try :
74+ listLen = names .index (removeName )
75+ except :
76+ print ("Debug Info: Failed to find " + removeName + " in list" )
77+ emails .remove (emails [listLen ])
78+ names .remove (names [listLen ])
79+ email .save ()
8780 def sendEmail ():
8881 subject = input ("What Is The Subject Of Your Message \n " )
8982 message = input ("Message\n Dear *[name]*,\n \n " )
83+ index = 0
9084 i = 0
9185 for i in range (len (names )):
86+ index += 1
87+ if (index > 10 ):
88+ index = 0
89+ s .quit ()
90+ try :
91+ s .starttls ()
92+ print ("Debug Info: TLS Worked" )
93+ except :
94+ print ("Debug Info: TLS Failed" )
95+ try :
96+ s .login (str (theirUsername ), str (password ))
97+ print ("Debug Info: Succesful you are now logged in and can send emails\n \n " )
98+ except :
99+ print ("Debug Info: Login Failed \n \n " )
92100 msg = MIMEMultipart () # create a message
93101 # setup the parameters of the message
94102 msg ['From' ]= theirUsername
95103 msg ['To' ]= emails [i ]
96104 msg ['Subject' ]= "This is TEST"
97- msg .attach (MIMEText ("Dear " + names [i ]+ ",\n " + message , 'plain' ))
105+ msg .attach (MIMEText ("Dear " + names [i ]+ ",\n \n " + message , 'plain' ))
98106 text = msg .as_string ()
99107 s .sendmail ("asteroid.dodge.devs@gmail.com" , emails [i ], text )
100108 print ("Sent, " + text )
101109 msg = ""
102110 def choose ():
103- choice = input ("What do you want to do\ n Add An Emailfrom you sending list(A)\n Remove an email from you sending list(R)\n Send an Email(S) \n Stop(F )\n " )
111+ choice = input ("What do you want to do: \n \ n Add An Email from you sending list(A)\n Remove an email from you sending list(R)\n Send an Email(S)\n " )
104112
105113 if choice == "A" :
106114 email .addEmail ()
115+ email .choose ()
107116 elif choice == "R" :
108117 email .removeEmail ()
118+ email .choose ()
109119 elif choice == "S" :
110120 email .sendEmail ()
111- elif choice == "F" :
112- sys .exit ()
113- else :
114121 email .choose ()
115- email .choose ()
122+ else :
123+ print ("Debug Info: Session Finnished" )
116124
117125email .loginSMTP ()
118126email .choose ()
0 commit comments