-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.py
More file actions
28 lines (22 loc) · 948 Bytes
/
test.py
File metadata and controls
28 lines (22 loc) · 948 Bytes
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
from smtp2discord import Smtp2DiscordController, Smtp2DiscordHandler
from glob import glob
import smtplib, aiohttp, asyncio
from secret import WEBHOOK_URL
async def deleteHandlerMessages(handler):
async with aiohttp.ClientSession() as session:
for message in handler.messages:
if "id" in message:
async with session.delete(WEBHOOK_URL + "/messages/" + message["id"]): pass
handler = Smtp2DiscordHandler(WEBHOOK_URL, attachOriginal=True, wait=True)
controller = Smtp2DiscordController(handler, "127.0.0.1", 2525)
controller.start()
print(controller.hostname, controller.port)
server = smtplib.SMTP("127.0.0.1", 2525)
try:
for emailFile in glob("*.eml"):
with open(emailFile, "rb") as messageFile:
server.sendmail("test@asdf.lan", "test2@asdf.lan", messageFile.read())
finally:
input("Press RETURN to delete test messages and stop server")
asyncio.run(deleteHandlerMessages(handler))
controller.stop()