Skip to content

Commit 3ccb990

Browse files
committed
Validity checking of count integer
1 parent 47d8546 commit 3ccb990

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

emailbomber.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,34 @@
1111
else: #Otherwise, reads saved user credentials.
1212
sender = open("User_Credentials/sender.txt", "rt").read() #Reads saved user gmail.
1313
app_password = open("User_Credentials/app_password.txt", "rt").read() #Reads saved user app password.
14+
1415
print("If you would like to spam more than one email, separate the emails by commas (example@gmail.com, example2@hotmail.com, example3@myspace.com)") #Tells user how to email-bomb more than one email.
1516
receiver = input("Specify the email(s) you would like to email-bomb -> ") #Enter the email(s) that you would like to email-bomb.
1617
message = input("Enter your email-bomber message -> ") #The message that the email user(s) will receive.
17-
try:
18-
count = int(input("Enter a number for the amount of emails to be sent -> ")) #The amount of emails to be sent to the receiver(s).
19-
except ValueError:
20-
print("Please enter a number for the amount of emails to be sent.")
21-
input("Press enter to exit.")
22-
quit()
18+
19+
# Loop until valid count value is given
20+
while(True):
21+
try:
22+
count = int(input("Enter a number for the amount of emails to be sent -> ")) #The amount of emails to be sent to the receiver(s).
23+
except ValueError:
24+
print("Please enter an integer for the amount of emails to be sent.")
25+
except KeyboardInterrupt:
26+
print("Goodbye!")
27+
quit()
28+
29+
if count <= 0:
30+
print("Count must be positive. Received", count)
31+
continue
32+
break
33+
2334
#Server
2435
server = smtplib.SMTP("smtp.gmail.com",587) #Initializes SMTP server.
2536
server.starttls() #Start SMTP server.
2637

2738
try: #Attempts to log in to user's gmail account.
2839
server.login(user= sender, password= app_password) #Logins to user's account.
2940
except smtplib.SMTPAuthenticationError as error: #Incorrect credentials inputted by user.
30-
print("\nError:\nMake sure the Gmail address that you inputted is the same as the gmail account you have created an app password for.\nDouble check your Gmail and app password.")
41+
print("\nError: Make sure the Gmail address that you inputted is the same as the Gmail account you have created an app password for.\nAlso, double-check your Gmail and app password.")
3142
print(f"{error}")
3243
input("Enter to exit...")
3344
quit() #Quits program.
@@ -40,7 +51,7 @@
4051
open("User_Credentials/app_password.txt", "xt").write(app_password) #Creates and saves user's Gmail app password to User_Credentials folder.
4152
input("\nYour credentials have been saved, so you do not have to repeat this process.\nTo change your credentials, go to User_Credentials and change your file information.\nPress enter to continue...")
4253
except OSError: #Operating system error.
43-
print("\nError:\nThere was an error saving your credentials.")
54+
print("\nError: There was an error saving your credentials.")
4455

4556
print("\nEmail-bomber has started...\n")
4657

@@ -51,9 +62,9 @@
5162
server.sendmail(from_addr= sender, to_addrs=email_receiver, msg=message) #Sends email to receiver.
5263
print("Email sent successfully!")
5364
except smtplib.SMTPException as error:
54-
print(f"Error:\n{error}")
65+
print(f"Error: {error}")
5566
continue
5667

5768

58-
input("\nEmail-bomber was successful...\nEnter to exit...") #Email-bomber finished.
69+
input("\nEmail-bomber was successful...\nPress enter to exit...") #Email-bomber finished.
5970
server.close() #Closes server.

0 commit comments

Comments
 (0)