mirror of
https://github.com/FAUSheppy/python-asio-smtp
synced 2025-12-06 10:01:35 +01:00
38 lines
1.1 KiB
Python
Executable File
38 lines
1.1 KiB
Python
Executable File
#!/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()
|