-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPySSMC.py
More file actions
168 lines (150 loc) · 4.36 KB
/
Copy pathPySSMC.py
File metadata and controls
168 lines (150 loc) · 4.36 KB
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
168
#
# -=-=-=-=- PySSMC v0.0.1 -=-=-=-=-
# Author: Bar Tselenchuk
# Source Code: https://github.com/bartselen/PySSMC/
#
# LICENSE:
# This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License.
# To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/.
#
import socket
import ssl
import base64
import getpass
import sys
import getopt
SERVERIP = "smtp.gmail.com"
PORT = 25
USERNAME = "bartselen@gmail.com"
PASSWORD = ""
RCPTLIST = []
_verbose = 0
MSGSUBJECT = "Get Ready!"
MSGCONTENT = "Frusta was here"
def usage():
print "Usage: pyssmc.py [-v || --verbose]"
scc = None
print "PySSMC Client v0.0.1"
def main(argv):
global USERNAME
global PASSWORD
global RCPTLIST
global MSGSUBJECT
global MSGCONTENT
global scc
try:
opts, args = getopt.getopt(argv, "v", ["verbose"])
except getopt.GetoptError:
usage()
sys.exit(2)
for opt, arg in opts:
if opt in ("-v", "--verbose"):
global _verbose
_verbose = 1
USERNAME = raw_input("Enter email address: ")
PASSWORD = getpass.getpass()
AUTH = False
cSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print "Connecting to " + SERVERIP + " on port " + str(PORT)
cSocket.connect((SERVERIP, PORT))
recv = cSocket.recv(1024)
if _verbose == 1:
print "<< " + recv
cSocket.send("EHLO\r\n")
if _verbose == 1:
print ">> EHLO\r\n"
recv = cSocket.recv(1024)
if _verbose == 1:
print "<< " + recv
command = "STARTTLS\r\n"
cSocket.send(command)
if _verbose == 1:
print ">> STARTLS\r\n"
recv = cSocket.recv(1024)
if _verbose == 1:
print "<< " + recv
scc = ssl.wrap_socket(cSocket, ssl_version=ssl.PROTOCOL_SSLv23)
scc.send('auth login\r\n')
if _verbose == 1:
print ">> auth login\r\n"
recv = scc.recv(1024)
if _verbose == 1:
print "<< " + recv
scc.send(base64.b64encode(USERNAME)+'\r\n')
if _verbose == 1:
print ">> " + base64.b64encode(USERNAME)+'\r\n'
recv = scc.recv(1024)
if _verbose == 1:
print "<< " + recv
scc.send(base64.b64encode(PASSWORD)+'\r\n')
if _verbose == 1:
print ">> " + base64.b64encode(PASSWORD)+'\r\n'
recv = scc.recv(1024)
if _verbose == 1:
print "<< " + recv
print "Login successful"
while True:
scc.send("MAIL FROM:<"+USERNAME+">\r\n")
if _verbose == 1:
print ">> MAIL FROM:<"+USERNAME+">\r\n"
recv = scc.recv(1024)
if _verbose == 1:
print "<< " + recv
break
RECPT = raw_input("Enter recipient list terminated by -1")
RCPTLIST.append(RECPT)
while RECPT != "-1":
RECPT = raw_input("Enter recipient: ")
if RECPT != "-1":
RCPTLIST.append(RECPT)
for mail in RCPTLIST:
while True:
scc.send("RCPT TO:<"+mail+">\r\n")
if _verbose == 1:
print ">> RCPT TO:<"+mail+">\r\n"
recv = scc.recv(1024)
if _verbose == 1:
print "<< " + recv
if "250 2.1.5 OK" in recv:
break
MSGSUBJECT = raw_input("Message subject: ")
MSGCONTENT = raw_input("Message content: ")
while True:
scc.send("DATA\r\n")
if _verbose == 1:
print ">> DATA\r\n"
recv = scc.recv(1024)
if _verbose == 1:
print "<< " + recv
if "354" in recv and "Go ahead" in recv:
break
while True:
scc.send("Subject: " + MSGSUBJECT + "\r\n"+ MSGCONTENT + "\r\n.\r\n")
if _verbose == 1:
print ">> Subject: " + MSGSUBJECT + "\r\n"+ MSGCONTENT + "\r\n.\r\n"
recv = scc.recv(1024)
if _verbose == 1:
print "<< " + recv
if "250" in recv:
break
else:
if _verbose == 1:
print recv
print "Email has been sent!"
while True:
scc.send("QUIT")
if _verbose == 1:
print ">> QUIT"
recv = scc.recv(1024)
if _verbose == 1:
print "<< " + recv
if "221 2.0.0" in recv:
break
if _verbose == 1:
print recv
input()
print "Closing connection."
scc.close()
cSocket.close()
if __name__ == "__main__":
main(sys.argv[1:])