forked from Mailu/Mailu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreply_test.py
executable file
·84 lines (70 loc) · 2.05 KB
/
reply_test.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
import smtplib
import imaplib
import time
import sys
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
msg = MIMEMultipart()
msg['From'] = "admin@mailu.io"
msg['To'] = "replyusea@mailu.io"
msg['Subject'] = "Reply Test"
msg.attach(MIMEText("Reply Text", 'plain'))
try:
smtp_server = smtplib.SMTP('localhost')
smtp_server.set_debuglevel(1)
smtp_server.connect('localhost', 587)
smtp_server.ehlo()
smtp_server.starttls()
smtp_server.ehlo()
smtp_server.login("admin@mailu.io", "password")
smtp_server.sendmail("admin@mailu.io", "replyuser@mailu.io", msg.as_string())
smtp_server.quit()
except:
sys.exit(25)
time.sleep(30)
# check original target
try:
imap_server = imaplib.IMAP4_SSL('localhost')
imap_server.login('replyuser@mailu.io', 'password')
except Exception as exc:
print("Failed with:", exc)
sys.exit(110)
stat, count = imap_server.select('inbox')
try:
stat, data = imap_server.fetch(count[0], '(UID BODY[TEXT])')
except :
sys.exit(99)
if "Reply Text" in str(data[0][1]):
print("Success: Mail is in target inbox")
else:
print("Failed receiving email in target inbox")
sys.exit(99)
typ, data = imap_server.search(None, 'ALL')
for num in data[0].split():
imap_server.store(num, '+FLAGS', '\\Deleted')
imap_server.expunge()
imap_server.close()
imap_server.logout()
# check original/replied user
try:
imap_server = imaplib.IMAP4_SSL('localhost')
imap_server.login('admin@mailu.io', 'password')
except Exception as exc:
print("Failed with:", exc)
sys.exit(110)
stat, count = imap_server.select('inbox')
try:
stat, data = imap_server.fetch(count[0], '(UID BODY[TEXT])')
except :
sys.exit(99)
if "Cause this is just a test" in str(data[0][1]):
print("Success: Reply is in original inbox")
else:
print("Failed receiving reply in original inbox")
sys.exit(99)
typ, data = imap_server.search(None, 'ALL')
for num in data[0].split():
imap_server.store(num, '+FLAGS', '\\Deleted')
imap_server.expunge()
imap_server.close()
imap_server.logout()