-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathpostfix-telnet
More file actions
executable file
·45 lines (41 loc) · 1.32 KB
/
postfix-telnet
File metadata and controls
executable file
·45 lines (41 loc) · 1.32 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
#!/usr/bin/python
import pexpect
import sys
import base64
email_to = None
email_from = None
login = None
password = None
hostname = None
telnet_session = pexpect.spawn('telnet ' + hostname + ' 25')
telnet_session.logfile_read = sys.stdout
telnet_session.logfile = sys.stdout
connect = telnet_session.expect('220')
telnet_session.sendline ('ehlo ' + hostname)
telnet_session.expect(['250'])
telnet_session.sendline('auth login')
telnet_session.expect('VXNlcm5hbWU6', timeout=2)
telnet_session.sendline(base64.b64encode(login))
telnet_session.expect('UGFzc3dvcmQ6', timeout=2)
telnet_session.sendline(base64.b64encode(password))
index = telnet_session.expect(['succe', 'authentication failure'], timeout=5)
if index == 0:
print "auth ok"
else:
print "auth failed with index ", index
telnet_session.sendline("MAIL FROM:<" + email_from + ">")
telnet_session.expect(['Ok', 'ok'])
telnet_session.sendline('RCPT TO:<' + email_to + '>')
index = telnet_session.expect(['Ok', 'ok', 'address rejected'])
telnet_session.sendline('DATA')
#telnet_session.sendline('Subject: Telnet test')
telnet_session.sendline('This message was sent by telnet')
telnet_session.sendline('kthxbye')
telnet_session.sendline('.')
if index == 0 or index == 1:
print "SUCCESS"
elif index == 2:
print "FAIL"
else:
print 'unknown error'
telnet_session.sendline('QUIT')