mailmonster/worker.py
2022-02-07 15:05:06 +01:00

30 lines
No EOL
595 B
Python

#!/usr/bin/env python3
import pathlib
from classes.config import Config
from classes.mission import Mission
from classes.smtp import SMTP
config = Config.fromFile("settings.ini")
tempdir = config.getTempDir()
if not tempdir.exists():
tempdir.mkdir()
elif not tempdir.is_dir():
raise ValueError(f"Temp Dir {str(tempdir)} exists and is not a directory.")
messages = []
for f in tempdir.glob("*.mmm"):
mission = Mission.fromFile(f)
messages.append(mission.to_message())
f.unlink()
smtp = SMTP.fromConfig(config)
for message in messages:
smtp.send_message(message)