blob: fa6e16b046676b1201dac0091cd90ebdefa43faf (
plain)
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
|
import asyncio
import quopri
from aiosmtpd.controller import Controller
class PrintHandler:
async def handle_RCPT(self, server, session, envelope, address, rcpt_options):
envelope.rcpt_tos.append(address)
return '250 OK'
async def handle_DATA(self, server, session, envelope):
print('Message from %s' % envelope.mail_from)
print('Message for %s' % envelope.rcpt_tos)
print('Message data:\n')
headers, body = envelope.content.decode('utf8').split("\r\n\r\n", maxsplit=1)
if "Content-Transfer-Encoding: quoted-printable" in headers:
body = quopri.decodestring(body).decode('utf8')
print(headers)
print()
print(body)
print()
print('End of message')
return '250 Message accepted for delivery'
if __name__ == '__main__':
controller = Controller(PrintHandler(), hostname="localhost", port=2525)
controller.start()
input()
|