Add some debugging
parent
4e1e9345a7
commit
a1981f23ab
|
@ -1,6 +1,7 @@
|
|||
FROM python:alpine
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
RUN pip install --no-cache requests configargparse xdg https://github.com/aio-libs/aiosmtpd/archive/refs/heads/master.zip
|
||||
RUN pip install --no-cache requests configargparse xdg aiosmtpd
|
||||
COPY ./libertyforward.py .
|
||||
EXPOSE 25
|
||||
CMD ["python", "/usr/src/app/libertyforward.py"]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from time import sleep
|
||||
import requests
|
||||
from asyncio import new_event_loop
|
||||
from aiosmtpd.controller import UnthreadedController as Controller
|
||||
from aiosmtpd.controller import Controller
|
||||
from configargparse import ArgParser
|
||||
from xdg import xdg_config_home
|
||||
|
||||
|
@ -27,10 +27,10 @@ class MailerHandlerMixin:
|
|||
self._api_token = value
|
||||
|
||||
|
||||
class KingMailerHandler(MailerHandlerMixin):
|
||||
class KingMailerHandler(object):
|
||||
|
||||
async def handle_DATA(self, server, session, envelope):
|
||||
print('Incoming mesage from: {}'.format(envelope.mail_from))
|
||||
print('Incoming mesage from: {}'.format(envelope.mail_from), flush=True)
|
||||
payload = {
|
||||
'mail_from': envelope.mail_from,
|
||||
'rcpt_to': envelope.rcpt_tos,
|
||||
|
@ -40,18 +40,23 @@ class KingMailerHandler(MailerHandlerMixin):
|
|||
response = requests.post('https://api.kingmailer.co/api/v1/send/raw', data=payload, headers=headers)
|
||||
print(response)
|
||||
if response.ok:
|
||||
print('Message accepted')
|
||||
print('Message accepted', flush=True)
|
||||
return '250 Message accepted for delivery'
|
||||
else:
|
||||
print('Could not process')
|
||||
print('Could not process', flush=True)
|
||||
return '500 Could not process your message'
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print('Starting LibertyForward', flush=True)
|
||||
args = parse_args()
|
||||
loop = new_event_loop()
|
||||
handler = KingMailerHandler()
|
||||
handler.api_token = args.api_token
|
||||
controller = Controller(handler, hostname='127.0.0.1', port=25, loop=loop)
|
||||
controller.begin()
|
||||
loop.run_forever()
|
||||
controller = Controller(handler, hostname='127.0.0.1', port=25)
|
||||
print('Starting controller thread', flush=True)
|
||||
controller.start()
|
||||
while True:
|
||||
try:
|
||||
sleep(1)
|
||||
except:
|
||||
break
|
||||
|
|
Loading…
Reference in New Issue