This commit is contained in:
Yannik Schmidt
2022-10-09 12:41:43 +02:00
commit dfa776ddf9

37
server.py Executable file
View File

@@ -0,0 +1,37 @@
#!/usr/bin/python3
import aiosmtpd.controller
import email
import email.policy
#import aiosmtpd.smtp.AuthResult, aiosmtpd.smtp.LoginPassword
USER = "test"
PASS = "test123"
class CustomSMTPHandler:
async def handle_DATA(self, server, session, envelope):
mail = email.message_from_bytes(envelope.content, policy=email.policy.default)
print(mail.get("subject"))
print(mail.get_body())
return '250 OK'
async def handleAUTH(server, session, envelope, mechanism, auth_data):
username = auth_data.login
password = auth_data.password
print("Auth Callback")
if username == USER and password == PASS:
return '235 Authentication successful'
#return aiosmtpd.smtp.AuthResult(success=True)
else:
assert(False)
return 'None'
#return aiosmtpd.smtp.AuthResult(success=False)
if __name__ == "__main__":
handler = CustomSMTPHandler()
server = aiosmtpd.controller.Controller(handler, hostname="0.0.0.0", port=8025)
server.start()
input("Server started. Press Return to quit.")
server.stop()