28
28
29
29
l = "smtp.gmail.com"
30
30
s = smtplib .SMTP (l , 587 )
31
+ listLen = 0
31
32
32
33
class email :
33
34
def save ():
35
+ print (emails )
36
+ print (names )
34
37
theLists = open ("lists.py" , "w" )
35
38
stringToSave = 'names = ['
36
- for i in range (len (names )- 2 ):
39
+ for i in range (len (names )- 1 ):
37
40
stringToSave = stringToSave + '"' + names [i ]+ '",'
38
41
stringToSave = stringToSave + '"' + names [(len (names )- 1 )]+ '"]\n emails = ['
39
42
i = 1
40
- for i in range (len (emails )- 2 ):
43
+ for i in range (len (emails )- 1 ):
41
44
stringToSave = stringToSave + '"' + emails [i ]+ '",'
42
45
stringToSave = stringToSave + '"' + emails [(len (emails )- 1 )]+ '"]'
43
- theLists .write (stringToSave )
46
+ theLists .write (str ( stringToSave ) )
44
47
print (stringToSave )
45
48
def loginSMTP ():
46
49
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)
58
50
theirUsername = str (input ("What is your username \n " ))
59
51
password = str (input ("What is your password \n " ))
60
- print ("Debug Info: Username, " + username + " Password, " + password )
52
+ print ("Debug Info: Username, " + theirUsername + " Password, " + password )
61
53
# Authentication
62
54
try :
63
55
s .starttls ()
@@ -66,53 +58,69 @@ def loginSMTP():
66
58
print ("Debug Info: TLS Failed" )
67
59
try :
68
60
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 " )
70
62
except :
71
- print ("It did not work " )
63
+ print ("Debug Info: Login Failed \n \n " )
72
64
def addEmail ():
73
65
nameInput = str (input ("What is the Name you would like to append\n " ))
74
66
names .append (nameInput )
75
67
emailInput = str (input ("What is the email of the reciver\n " ))
76
68
emails .append (emailInput )
77
- email .save
69
+ email .save ()
78
70
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 ()
87
80
def sendEmail ():
88
81
subject = input ("What Is The Subject Of Your Message \n " )
89
82
message = input ("Message\n Dear *[name]*,\n \n " )
83
+ index = 0
90
84
i = 0
91
85
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 " )
92
100
msg = MIMEMultipart () # create a message
93
101
# setup the parameters of the message
94
102
msg ['From' ]= theirUsername
95
103
msg ['To' ]= emails [i ]
96
104
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' ))
98
106
text = msg .as_string ()
99
107
s .
sendmail (
"[email protected] " ,
emails [
i ],
text )
100
108
print ("Sent, " + text )
101
109
msg = ""
102
110
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 " )
104
112
105
113
if choice == "A" :
106
114
email .addEmail ()
115
+ email .choose ()
107
116
elif choice == "R" :
108
117
email .removeEmail ()
118
+ email .choose ()
109
119
elif choice == "S" :
110
120
email .sendEmail ()
111
- elif choice == "F" :
112
- sys .exit ()
113
- else :
114
121
email .choose ()
115
- email .choose ()
122
+ else :
123
+ print ("Debug Info: Session Finnished" )
116
124
117
125
email .loginSMTP ()
118
126
email .choose ()
0 commit comments