|
1 | | -#Built-in library's. |
| 1 | +#Built-in libraries |
2 | 2 | import smtplib |
3 | 3 | from os import access, path, mkdir |
4 | 4 | from email.message import EmailMessage |
5 | 5 |
|
6 | | -print(f"{open('Welcome/welcome.txt', encoding='UTF-8').read()}\n\n") #Welcomes user. |
| 6 | +# Welcomes user |
| 7 | +print(f"{open('Welcome/welcome.txt', encoding='UTF-8').read()}\n\n") |
7 | 8 |
|
8 | | -#User inputs |
9 | | -if not path.exists("User_Credentials"): #If User_Credentials does not exist, asks for user credentials. |
10 | | - sender = input("Enter the Gmail address you would like to send emails from (example@gmail.com) -> ") #The gmail address that emails will be sent from e.g. example@gmail.com. |
11 | | - app_password = input("Enter the app's password (xxxx xxxx xxxx xxxx)-> ") #The app's password that was created from the Gmail address e.g. alig maou tajh jagq. |
12 | | -else: #Otherwise, reads saved user credentials. |
13 | | - sender = open("User_Credentials/sender.txt", "rt").read() #Reads saved user gmail. |
14 | | - app_password = open("User_Credentials/app_password.txt", "rt").read() #Reads saved user app password. |
| 9 | +# User inputs |
| 10 | +if not path.exists("User_Credentials"): |
| 11 | + # If User_Credentials does not exist, asks for user credentials |
| 12 | + sender = input("Enter the Gmail address you would like to send emails from (example@gmail.com) -> ") |
| 13 | + app_password = input("Enter the app's password (xxxx xxxx xxxx xxxx) -> ") |
| 14 | +else: |
| 15 | + # Otherwise, reads saved user credentials |
| 16 | + sender = open("User_Credentials/sender.txt", "rt").read() |
| 17 | + app_password = open("User_Credentials/app_password.txt", "rt").read() |
| 18 | + |
| 19 | +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)") |
| 20 | + |
| 21 | +# Enter the email(s) that you would like to email-bomb |
| 22 | +receiver = input("Specify the email(s) you would like to email-bomb -> ") |
| 23 | + |
| 24 | +# Enter the subject for the emails |
| 25 | +subject = input("Enter the subject for your email-bomber message -> ") |
| 26 | + |
| 27 | +# Enter the message that the email user(s) will receive |
| 28 | +msg = input("Enter your email-bomber message -> ") |
15 | 29 |
|
16 | | -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. |
17 | | -receiver = input("Specify the email(s) you would like to email-bomb -> ") #Enter the email(s) that you would like to email-bomb. |
18 | | -msg = input("Enter your email-bomber message -> ") #The message that the email user(s) will receive. |
19 | 30 | message = EmailMessage() |
20 | 31 | message.set_content(msg, subtype="plain", charset='us-ascii') |
21 | | -message = str(message) |
| 32 | +message["Subject"] = subject# Set the subject for the email |
22 | 33 |
|
23 | | -# Loop until valid count value is given |
24 | | -while(True): |
| 34 | +# Loop until a valid count value is given |
| 35 | +whileTrue: |
25 | 36 | try: |
26 | | - 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). |
| 37 | + count = int(input("Enter a number for the amount of emails to be sent -> ")) |
27 | 38 | except ValueError: |
28 | 39 | print("Please enter an integer for the amount of emails to be sent.") |
29 | 40 | except KeyboardInterrupt: |
30 | 41 | print("Goodbye!") |
31 | 42 | quit() |
32 | | - |
| 43 | + |
33 | 44 | if count <= 0: |
34 | 45 | print("Count must be positive. Received", count) |
35 | 46 | continue |
36 | 47 | break |
37 | 48 |
|
38 | | -#Server |
39 | | -server = smtplib.SMTP("smtp.gmail.com",587)#Initializes SMTP server. |
40 | | -server.starttls()#Start SMTP server. |
| 49 | +#Server |
| 50 | +server = smtplib.SMTP("smtp.gmail.com",587) |
| 51 | +server.starttls() |
41 | 52 |
|
42 | | -try: #Attempts to log in to user's gmail account. |
43 | | - server.login(user= sender, password= app_password) #Logins to user's account. |
44 | | -except smtplib.SMTPAuthenticationError as error: #Incorrect credentials inputted by user. |
| 53 | +# Attempts to log in to the user's Gmail account |
| 54 | +try: |
| 55 | + server.login(user=sender, password=app_password) |
| 56 | +except smtplib.SMTPAuthenticationError as error: |
45 | 57 | 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.") |
46 | 58 | print(f"{error}") |
47 | 59 | input("Enter to exit...") |
48 | | - quit()#Quits program. |
| 60 | + quit() |
49 | 61 |
|
50 | 62 | try: |
51 | | - if not path.exists("User_Credentials"): #If user credentials does not exist, creates and saves credential files. |
52 | | - #If there are no errors in credentials, save user information after SMTP verification. |
53 | | - mkdir("User_Credentials") #Creats User_Credentials folder. |
54 | | - open("User_Credentials/sender.txt", "xt").write(sender) #Creates and saves user's Gmail address to User_Credentials folder. |
55 | | - open("User_Credentials/app_password.txt", "xt").write(app_password) #Creates and saves user's Gmail app password to User_Credentials folder. |
| 63 | + if not path.exists("User_Credentials"): |
| 64 | + # If user credentials do not exist, create and save credential files |
| 65 | + # If there are no errors in credentials, save user information after SMTP verification |
| 66 | + mkdir("User_Credentials") |
| 67 | + open("User_Credentials/sender.txt", "xt").write(sender) |
| 68 | + open("User_Credentials/app_password.txt", "xt").write(app_password) |
56 | 69 | 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...") |
57 | | -except OSError:#Operating system error. |
| 70 | +except OSError: |
58 | 71 | print("\nError: There was an error saving your credentials.") |
59 | 72 |
|
60 | 73 | print("\nEmail-bomber has started...\n") |
61 | 74 |
|
62 | | -for i in range(count): #Amount of messages to be sent. |
63 | | - for email_receiver in receiver.split(","): #Loops through emails to send emails to. |
64 | | - try: |
65 | | - print(f"Email-bombing {email_receiver}...") |
66 | | - server.sendmail(from_addr= sender, to_addrs=email_receiver, msg=message) #Sends email to receiver. |
| 75 | +for i in range(count): |
| 76 | + # Amount of messages to be sent |
| 77 | + for email_receiver in receiver.split(","): |
| 78 | + # Loops through emails to send emails to |
| 79 | + try: |
| 80 | + print(f"Email-bombing {email_receiver}...") |
| 81 | + server.sendmail(from_addr=sender, to_addrs=email_receiver, msg=message.as_string()) |
67 | 82 | print("Email sent successfully!") |
68 | 83 | except smtplib.SMTPException as error: |
69 | 84 | print(f"Error: {error}") |
70 | 85 | continue |
71 | 86 |
|
72 | | - |
73 | | -input("\nEmail-bomber was successful...\nPress enter to exit...") #Email-bomber finished. |
74 | | -server.close() #Closes server. |
| 87 | +input("\nEmail-bomber was successful...\nPress enter to exit...") |
| 88 | +server.close() |
0 commit comments