This repository has been archived by the owner on Jul 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
email_sender.py
168 lines (141 loc) · 5.58 KB
/
email_sender.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
'''
Author : jimutbahanpal@yahoo.com
This software can be used to send enormous amount of spam email using google's smtp library.
The author is not responsible for any trouble caused by this software. Don't spread troubles unless needed to!
...remember
WITH GREAT POWERS COMES GREAT RESPONSIBILITIES
Use as you want...
'''
import smtplib # importing the smtplib for google mail
import colorama
from colorama import Fore, Back, Style # for cool coloring stuffs!
import sqlite3 # for db stuffs!
from datetime import datetime # date time stuffs
from email.message import EmailMessage
from email.headerregistry import Address
from email.utils import make_msgid
import getpass # for password
conn = sqlite3.connect('spam_email.sqlite')
cur = conn.cursor()
# no sub content temp img date start end send_addr recv_addr omail
cur.executescript('''
CREATE TABLE IF NOT EXISTS MAIL (
no INTEGER,
sub TEXT,
content TEXT,
temp TEXT,
date DATE,
start DATE,
end DATE,
send_addr TEXT,
recv_addr TEXT
);
''')
# sender details
#username # write the username here
#password # write the password here
# paljimutbahan@gmail.com
class mail_sender():
template = """\
<html>
<title> This is the title</title>
<head> Some head in this place</head>
<body>
<h1>
Header of the mail
</h1>
<b>
This is bold!
</b>
<i>
This is italics
</i>
<u>
This is underline
</u>
<p>
Salut!
</p>
<p>Follow on github!
<a href="https://github.com/Jimut123">
recipie
</a>
</p>
</body>
</html>
"""
content = """\
Rse!
Cela ressemble à un excellent recipie[1] déjeuner.
[1] http://www.yummly.com/recipe/Roasted-Asparagus-Epicurious-203718
--Pepé
"""
def get_timestap():
return datetime.now().isoformat(timespec='seconds')
def sendmail(senderName, # Name of the sender
recvName, # Name of the recipient here
subject, # Give the subject here
template, # Send the template here
content, # normal text
img_flag=False, # By default image flag is set to false
img_name="", # add image name here
bckupmsgfilename="outgoingmsg.txt" # add the name of the backup msg here
):
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
global username, password
server.login(username, password) # load the server
message = EmailMessage()
asparagus_cid = make_msgid()
message['Subject'] = subject
message['From'] = senderName
message['To'] = recvName
#setting the contents here, just the mail here
message.set_content(content)
#Adding the template here and formatting to html
message.add_alternative(template.format(asparagus_cid=asparagus_cid[1:-1]), subtype='html')
# Now add the related image to the html part.
'''
if img_flag == True:
with open(img_name,'rb') as img:
message.get_payload()[1].add_related(img.read(),'image','jpeg',cid=asparagus_cid)
'''
# Make a local copy of what we are going to send.
with open(bckupmsgfilename, 'wb') as f:
f.write(bytes(message))
server.sendmail(senderName, recvName, str(message))
server.quit()
if __name__=='__main__':
# to send the mail
number_mails = int(input(Fore.BLUE+"Enter the number of mails you want to send [LIMIT is 10,000 for Google (gmail) SMTP] : "))
print(Fore.BLUE+"SENDING ",Fore.RED+str(number_mails),Fore.BLUE+" one by one ... ")
recv_name = input(Fore.GREEN+"Enter the receiver's address : ")
obj = mail_sender # creating the object of the email sender class
sub = input(Fore.GREEN+"Enter the subject of the email : ")
global username,password
username = input(Fore.RED+"Enter the email address (username) of sender : ")
str1 = Fore.RED+"Enter the password of ",username," : "
password = getpass.getpass(str1)
start_time = obj.get_timestap()
print(Fore.GREEN+" START TIME :: ",start_time)
num_sent = 0
for i in range(number_mails):
if i%5==0: # commiting after sending 5 emails sucessfully!
conn.commit()
try:
num_sent += 1
obj.sendmail(username,
recv_name,
sub,
obj.template,
obj.content,
False, # set : True for sending image
"roasted-asparagus.jpg",
"outgoingmsg.txt")
end_time = obj.get_timestap()
print(Fore.GREEN+"LOGS : ", Fore.GREEN,num_sent, sub, obj.content, Style.DIM+obj.template, start_time, start_time, end_time, username, recv_name)
cur.execute('''INSERT OR IGNORE INTO MAIL (no, sub, content, temp, date, start, end, send_addr, recv_addr)
VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ? )''', ( num_sent, sub, obj.content, obj.template, start_time, start_time, end_time, username, recv_name ) ) # stacks the link found at the bottom
except:
print(Fore.RED+"OOPS!!! SOMETHING WENT WRONG!")
conn.commit()